Dan makes an
interesting observation about syntax highlighting:
I noticed this the other day when I printed out the code for the compiler
module I’m working on. In the editor, with colored highlighting enabled, it
makes sense what’s going on, and everything’s reasonably obvious. On paper,
though, in black and white with no highlighting the lack of comments was much
more obvious, and the code itself didn’t make a whole lot of sense.
I have certainly made the same observation. Once in a while, I revert
to emacs to edit Java files and the absence of highlighting immediately puts an
extra burden on my eyes and my brain (and yes, I know about syntax highlighting
in emacs, I actually wrote a few elisp modes myself, but I stopped trying to
install such packages about five years ago when my sanity was on the brink of
leaving me).
However, I don’t follow Dan when he says:
I have noticed one interesting thing about using it [syntax highlighting],
though–I comment my code less.
I fail to see the logical connection between syntax highlighting ("read"
mode) and comments ("write" mode). Syntax highlighting is certainly not a
substitute for commenting your code.
Syntax highlighting is about… well, syntax: keywords, expressions,
well-formedness, etc…
Comments are about semantics. You don’t need to explain what a "for"
loop does, but it’s definitely a good practice to put a comment on top of such a
loop to explain the business logic inside. Syntax highlighting certainly
doesn’t cover this aspect, so don’t be lazy with your comments.
#1 by Iain on November 21, 2003 - 4:46 pm
I comment what I can’t immediately comprehend.
Syntax highlighting gives me lots of cues so I can mentally parse a block of code much faster than if it were black and white.
Thus, what needs a comment in black and white does not necessarily need a comment in TechniColor.
While one should indeed comment business logic, one should also comment such that one’s navigation of code is easy. Bear in mind that, as a Perl programmer, there can be a lot of meaning in just a few lines of my code.
cheers,
#2 by Sam Pullara on November 21, 2003 - 5:24 pm
Strangely, Emacs not only highlights my code but also prints it highlighted.
#3 by Aivars on November 22, 2003 - 2:07 am
“Strangely, Emacs not only highlights my code but also prints it highlighted.”
Even on b&w printer?
#4 by mjasnowski on November 24, 2003 - 12:40 pm
only emacs could pull that off
#5 by Google on November 14, 2004 - 2:13 pm
Tippo Sahib was so fond of los pollos/>
That many back then found it real gross/>
A hen saw him Zip it/>
And decided to Stuffit/>
Then pecked him real hard in los huevos
Search Google http://www.google.com/
#6 by Google on November 17, 2004 - 2:24 am
hurrah!
Search Google http://www.google.com/
#7 by Jerome on December 6, 2004 - 8:31 pm
When emacs prints something syntax-hightlighted it makes good use of bold for identifiers, and IIRC, lighter text for comments.