Syntax Off (2012)
kyleisom.net
kyleisom.net
One man's crutch is another man's perfectly reasonable tool. Is a carpenter's level a crutch?
> When I read a book, I don't want parts of speech highlighted in different colours
I have trouble discerning colours and I still use syntax highlighting. I don't think that there are people that are programmers but unable to read code unless all of the floats are purple. The highlighting mostly just tells me "this parsed correctly" and helps my eye track where e.g. string literals begin and end. I don't really see a reason to give either of those things up. If it's distracting, you could easily turn down the theme to just bold one or two keywords and string literals, which solves both of those two problems at least. Maybe go crazy and reverse the background on obvious syntax errors like unexpected symbols.
I rarely want to focus on the code itself and more just want to focus on the problem. Immediately highlighting code errors seems like a perfectly nice thing to do to that end. If I could just write a bunch of code quickly, riddled with syntax errors, and click some magic "okay editor, fix away!" button I'd be fine with that too.
To each their own I suppose.
"How I stopped [perfectly fine activity]... And why you should, too."
I do! In long conversations in novels I occasionally lose track of who is currently talking; normally it's really obvious as the next page of text doesn't make any sense until I backtrack to find where the speech got switched, though one time I finished a whole book where my protagonist had the wrong gender because I didn't realise that the prologue and the main text were written from different people's first-person perspectives...
It also reminds me of some anime fansubs, where series with lots of characters would have each character's subs written in their hair colour, which is really helpful for someone who has trouble disinguishing similar foreign voices from each other :P
Perhaps the actual story narrative needs to be clearer, by repeating the speaker's name more often.
I don't seem to have much problem with this in English, but it causes me no end of grief reading in a non-native language, I suppose because my grasp of context and eye for other cues is much shakier...
[I've read books where I'll get halfway through the book before realizing my entire conception of what's going on has been completely wrong due to confusion over who said something in the beginning of the book... I'll go back, re-read the crucial dialogue with the speakers swapped, and suddenly everything starts making sense... TT ]
Which is true, we used to joke that the C compiler on a VAX was so slow that you wanted to be really really sure it wasn't going to throw some crappy syntax error so you read through your code twice before submitting it. But a friend of mine from the Amiga community showed me that iterating fast often lead to faster code development than slower iteration. In both cases having your code in your head made for a better result, but someone who could iterate fast and hold the code in their head, always out performed the person on the slow path.
It can be hard to develop the discipline though.
Whatever metaphor you use, this is just dumb.
Books don't have syntax highlighting, but having never read a book that does, I can't say one way or the other that it is a terrible idea.
And actually, as I think about it more, books would be a nicer reading experience if conversations were highlighted, and if key person/place names where in a different color.
(Just like text in RPGs sometimes).
As a personal note, the first time I read it, I didn't realize that the colors were significant for a couple of chapters because, for some reason, I occasionally perceive black text on paper as being red, and thus it took me a while to realize that this text actually was printed in red.
And some books do do these things. Often thoughts are italic whereas spoken words are quoted. Pratchett puts Death's words in all caps.
> "The best way I can describe it is to compare it to reading a book. When I read a book, I don't want parts of speech highlighted in different colours. What I want to do is to read the book, to take in the information."
I would love to try reading a book with the same support. Nouns in red and adverbs in green. It would be fantastic! So much passive information available… Now I think I know what my next weekend project is.
This is what my code looked like:
// Initialise
for (i=0;i<3;++i) {
/* Do initialisation here!
niftyConfig = 1;
funkyValue = 2;
}
// Run forever
for (;;) {
/* So, this is where we do stuff! */
...
}
Syntax highlighting would have shown the problem instantly. In fact, the bug would never have happened.Anything that can increase the chance to catch an error is a good thing.
[EDITED for code formatting.]
* zazen: http://www.vim.org/scripts/script.php?script_id=3413
* zenesque: http://www.vim.org/scripts/script.php?script_id=3340
http://www.linusakesson.net/programming/syntaxhighlighting/
I still think it is nutty.
I use syntax highlighting, but I use very mellow colors that do not distract. The example given out in Akesson's article is a complete eyesore, however many text editors are like that and it's not that simple to change the color scheme in all of them.
I believe syntax highlighting can also spoil you if that's all you're used to. It is a good exercise to write and maintain some code in raw format, occasionally.
Personally I think it's enough just to highlight the reserved keywords and comments.
But the need for color seems too strong to fight with pure rationality. Perhaps it's enough that adding a little color to an environment we spend a significant amount of our lives in makes us happy. Since I have no taste, garishness doesn't bother me :)
Here's an example of color being used in a relatively staid place -- and paying for itself: https://plus.google.com/110440139189906861022/posts/UqyUZdqP...
Hopefully these considerations will be subsumed by new research by Bret Victor or Rune Madsen (http://vimeo.com/61113159).
For now, here's my preferred syntax highlighting, with just a dash of color in most usual places, but two colors for comments: http://i.imgur.com/H1h7M.png. (Why 2 comment colors? http://akkartik.name/post/2012-11-24-18-10-36-soc has the scoop.) Notice how the left pane is C++ and the right pane is my toy lisp, and the syntax kinda harmonizes.
Yes, highlighting language keywords is like capitalizing or bolding the unstressed words in English:
THERE IS A book ABOUT programming ON THE table.Disagree, it helps confirm you typed it correctly when you are trying to, and that you've named something incompatibly when you aren't. Thereby very likely preventing syntax/name errors before they happen.
Code is read more often than it's written, but it's skimmed more often than it's read. So making it easy to mentally jump around code without actually reading it is extremely valuable.
I've found this particularly valuable in Haskell because it lets you use arbitrary things in infix position. Now, this by itself is valuable for the same reason: it helps structure the code, neatly separating the operation from its arguments. Some things just make more sense infix. But visually, it's often hard to grasp when something is infix. This is not too bad with operators:
foo bar baz + qux 11 quux
but it's actually rather difficult with normal words infix: map solve problems `using` rpar rseq
Now compare this to the highlighted version: http://jelv.is/img/hs-syntax-hl.pngThe most important part of the above snippet is how "using" divides into two clear parts. And yet, on something like HN, this is a bit hard to follow: "using" looks like another word in a string of words--this is exactly what I want to avoid with the infix syntax!
In Emacs, at least, infix symbols--both operators and names in backticks--get highlighted in a different color. This immediately make the structure of the above code completely clear. Then, when I'm glancing through it, I can focus on the part I care about. (This example is particularly appropriate because the two halves do completely different things--the left one defines the computation and the right one specifies how to parallelize it; chances are I only care about one of the two at a time.)
I think that highlighting operators also explains why I've never had any real difficulties with Haskell's "symbol heavy" code.
This could be extended to a bunch of other structural distinctions I care about. For example, when reading Lisp code, I would love to have macros and functions highlighted differently. Macros generally represent some sort of code organization where functions are often part of the actual program logic; moreover, macros and functions behave very differently.
I vaguely remember somebody posting a lisp-y emacs-y setup of a synth coding environment of sorts that looked like heaven to me. (You'd quickly iterate on code with transforms that would shift the sound playing at all times and the colors would POP at you) It also makes me wonder how blind coders handle things. Does a pleasant yet distinct background noise when hovering over say, curly braces or parens, does that make sense to anybody else? I'm developing an itch here but I don't want to go it alone as it were.
Edit: also come to think of it, why isn't this stuff empirically tested? The right font faces and sizes for optimal readability, tabs vs spaces, camelCase vs snake_case, colors and which ones, all the classics. Where is the science?
Changing tone based on depth could be pretty interesting, as could tones representing things like unused variables.
Based on your preferences, you could also do things like have the noise grow unpleasant if you do something you shouldn't (e.g., reuse a variable name, write an impure function, etc.).
I found this interesting, as my reaction has been almost the complete opposite. I've never felt that syntax highlighting played a part in understanding code at a high level. Syntax highlighting is there for when I'm reading my code like a copy-editor. It (along with an inline linter) is there to make syntactical errors more obvious so I can deal with them as I make them.
And if he's meaning to compare it to prose, while they typically lack color (due more to the means of printing than the format, check out old manuscripts and they use color quite often), they use punctuation and other methods of emphasis like bold, italics, size, and underlining.
On the other hand, perhaps highlighting the syntax is to represent the structure of source code, or make it more readable. There is also a text highlight utility for text, called BeeLineReader (http://www.beelinereader.com/)
Personally I program Clojure, so there's not a lot of syntax to highlight--well, more than in scheme, for example--but I couldn't imagine life without brace matching (a dynamic kind of syntax highlighting).
Once you're used to the lack of color, go all the way and use a proportional font.
Much like the colour output of ls; beautiful on black, largely invisible on anything else.