News for hackers. Stuff that matters.
Re::syntax Off by tikhonj on Monday November 05, 2012 @02:37AM (#4742616)
It's an interesting idea.

I've actually gone the opposite way recently. In the past, I'd only have code highlighting. Different parts of the syntax would be rendered as different colors--nothing surprising.

However, recently I've been writing a lot of Haskell and OCaml. At least in Emacs, both Haskell and OCaml have an additional option to syntax highlighting with color: your code can also be highlighted with symbols. That is, parts of the syntax are not only displayed in a different color but actually displayed as a Unicode character rather than ASCII. As a moderately contrived example, something like

    \ a b c -> a >= b && b <= c || a /= c
would get displayed as:

    λ a b c → a ≥ b ∧ b ≤ c ∨ a ≢ c
Now, real code doesn't usually have symbols quite as dense; this example just shows a whole bunch of them at the same time.

I find the second snippet far easier to read than the first, especially if I'm just scanning over the code.

This is also a very good reason for using a typeface like Deja Vu Sans Mono: it can support all the symbols I could ever want. It's also very readable.

I personally find this, combined with syntax highlighting, extremely useful for reading code. Actually, thinking about this, I've found syntax highlighting even more useful for Haskell and OCaml than other languages, probably because they have very minimalist syntax. I really like the syntax, but the color does make the overall structure of any given function much more evident, which is nice.

Coincidentally, for the same readability reasons as above, I'm significantly warming up to Unicode identifiers. I think something like:

    set1 `union` set2
is not nearly as readable as

    set1 ∪ set2
And, as a bonus, the second version is easier to type:

    set1 \cup set2
Additionally, using Unicode identifiers and operators matches the way I write pseudocode. With the right identifiers, my Haskell code actually looks very close to what I would write on a whiteboard to explain some concept. That's one of the reasons I really like Haskell's syntax.

As an aside, the expression

    set1 `union` set2
is a perfect case study of why I find syntax highlighting useful. First of all, I think it's strictly better than the prefix version:

    union set1 set2
I've found being able to use arbitrary functions in an infix position can sometimes make certain expressions much more readable and natural.

However, if you're just scanning over the code, it might be easy to miss the backticks. Happily, in Emacs, operators get highlighted in a different color from normal identifiers. This includes things in backticks. So the `union` gets highlighted in a different color, making it obvious it's being used in an infix position.

Re::syntax Off by scrumper on Monday November 05, 2012 @07:20AM (#4743122)
I've become very used to this in Mathematica. That takes it a little further: Matrices look like matrices, greek letters are actual greek letters and division writes the parts as you'd see on paper - numerator over denominator. Any kind of mathematical code is vastly more readable this way. The way you access symbols is easy too: hit esc, type a short mnemonic, then hit esc again, for example esc-pi-esc gives you pi. Best of all, it's all stored as human-readable plaintext source under the covers. The display is just a convenience.

Can't wait for unicode identifiers and this kind of expression composition in general purpose languages like objc.

Re::syntax Off by ek on Monday November 05, 2012 @03:07AM (#4742672)
Languages like Scala have this sort of support for unicode built-in - many operators have Unicode aliases and it is possible for you to designate your own Unicode-named functions as well. There are some nice examples of meaningful syntactic sugar, like ⇒ for lambdas, ← for enumerators, and → for tuple building (all of which have =>, <-, and -> as ASCII equivalents).
Re::syntax Off by jimbokun on Monday November 05, 2012 @11:15AM (#4744169)
The Fortress language (recently discontinued) really pushed the boundaries of using mathematical notation in a programming language. The "mathematical" version looked like the pseudo-code examples many CS textbooks use.

Lots of examples here

http://stephane.ducasse.free.fr/Teaching/CoursAnnecy/0506-Ma...

Re::syntax Off by mercurial on Monday November 05, 2012 @07:21AM (#4743128)
Rust's syntax file for vim (and I assume emacs) does the same thing per default. It's quite nice, except when you rely on X's copy paste, which going to blindly copy the unicode characters.
Re::syntax Off by drothlis on Monday November 05, 2012 @09:36AM (#4743585)
> in Emacs, both Haskell and OCaml [...] can also be highlighted with symbols

And not just Haskell and OCaml: See for example https://github.com/drothlis/pretty-symbols

(though of course Haskell and OCaml might be much more suited to this kind of visualisation -- in python, say, you just get λ ≠ ≥ ≤).

Re::syntax Off by cabalamat on Monday November 05, 2012 @07:49AM (#4743207)
This:

> set1 ∪ set2

Looks good until someone confuses it with:

> set1 u set2

Having two characters that are similar enough to be confusing is bound to cause problems.

Re::syntax Off by yfr on Monday November 05, 2012 @02:53AM (#4742642)
This is amazing! Any idea if this is possible in vim?
Re::syntax Off by arnoooooo on Monday November 05, 2012 @03:08AM (#4742674)
Without changing the order of symbols, you can at least display some symbols as unicode with vanilla Vim. Here's an extract of my Lisp Vim config, which replaces lambda by λ :

  set conceallevel=2
  syntax keyword lispFunc lambda conceal cchar=λ
Re::syntax Off by reblochon on Monday November 05, 2012 @04:09AM (#4742781)
The best way I know to do it for Haskell is to use haskellConceal ( http://www.vim.org/scripts/script.php?script_id=3200 ), it display unicode characters but left the underlying ASCII untouched.
Re::syntax Off by tikhonj on Monday November 05, 2012 @03:00AM (#4742656)
There seems to be a plugin called unicode-haskell[1] for Vim. However, as I am obviously not a Vim user, I don't really know anything about it.

[1]: https://github.com/frerich/unicode-haskell

Re::syntax Off by yfr on Monday November 05, 2012 @03:12AM (#4742687)
Thanks this is exactly what I need, should make coding in functional languages a lot more readable. Actually it appears GHC supports the use of unicode characters for operators via packages and an extension[1], if it wasn't for your post I would not have discovered this, cheers!

[1]: http://www.haskell.org/haskellwiki/Unicode-symbols

Re::syntax Off by wladimir on Monday November 05, 2012 @07:21AM (#4743125)
I wouldn't recommend using that one. There is a newer plugin [1] that uses "after" in combination with conceal syntax to achieve the same effect but without buffer hacks on load/save.

[1] https://github.com/vim-scripts/Haskell-Conceal

Re::syntax Off by threedaymonk on Monday November 05, 2012 @10:38AM (#4743967)
Haskell-Conceal also works a lot better than unicode-haskell: it doesn't erroneously turn "\n" into "λn", and it replaces :: with a single-glyph equivalent so that signature and definition line up nicely.

Having said that, I still prefer <- and -> to ← and →, at least on screen: those Unicode arrowheads are too small on all the fixed-width fonts I've ever seen.

Re::syntax Off by wladimir on Tuesday November 06, 2012 @03:39AM (#4747668)
Those arrows are indeed pesky. In my fixed-width fonts (at least at the font size I'm using), → (->) and ⇒ (=>) look the same.
Re::syntax Off by evoxed on Monday November 05, 2012 @03:06AM (#4742671)
Seems I should've refreshed before posting (now deleted)! As you can see from the plugin file, applying the maps isn't all that complicated, though it certainly would be nice to have it built in. I'm not an emacs user, but I seem to recall using this feature before... anyone know if TextMate had this implemented?
Re::syntax Off by illicium on Monday November 05, 2012 @03:05AM (#4742668)
Re::syntax Off by jacobr on Monday November 05, 2012 @03:06AM (#4742670)
Combining :abbr and conceal could indeed reduce quite a lot of verbosity from JavaScript for instance.