November 21, 2003

Syntax highlighting

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.

Posted by cedric at November 21, 2003 04:24 PM
Comments

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,

Posted by: Iain at November 21, 2003 04:46 PM

Strangely, Emacs not only highlights my code but also prints it highlighted.

Posted by: Sam Pullara at November 21, 2003 05:24 PM

"Strangely, Emacs not only highlights my code but also prints it highlighted."

Even on b&w printer?

Posted by: Aivars at November 22, 2003 02:07 AM

only emacs could pull that off

Posted by: mjasnowski at November 24, 2003 12:40 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/

Posted by: Google at November 14, 2004 02:13 PM

hurrah!
Search Google http://www.google.com/

Posted by: Google at November 17, 2004 02:24 AM

When emacs prints something syntax-hightlighted it makes good use of bold for identifiers, and IIRC, lighter text for comments.

Posted by: Jerome at December 6, 2004 08:31 PM
Post a comment






Remember personal info?