[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-developer] On syntactic coloring of language

From: William Sit
Subject: Re: [Axiom-developer] On syntactic coloring of language
Date: Mon, 19 May 2014 08:56:06 -0400

Dear Tim:

Your reasoning is perfect for natural languages. For computer languages, I do think there is a purpose for certain highlighting of keywords and their associated punctuations, particularly when the correct language syntax frequently demands nested pairs of delimiters whose scopes may be more than a few lines, and where structural indentations may not be practical. Examples would be html, Mathematica and TeX/LaTeX. Thus, the reason for highlighting an IF-THEN-ELSE (as just one example) is not because readers can't recognize those keywords, but because readers may find it difficult to identify the extents indicated by the hyphens in IF-THEN-ELSE. Such highlighting benefits both the authors and the readers and has its role for better syntactic communication.

One should not compare or confuse the highlighting of, say, prepositions in natural languages with scope defining highlighting in programming languages.

That said, it is not good programming practice to have long scopes between paired delimiters, or for that matter, deeply nested pairs of delimiters.

I agree that those who choose color highlighting should choose colors carefully. I would prefer background coloring only and not text coloring, to avoid the precise problems you illustrated. Text emphasis should be shown using different typefaces, and in rare situations, a solid color like red.


On Mon, 19 May 2014 03:07:57 -0500
 address@hidden wrote:
I had a debate about syntax highlighting of languages, an idea that dates back to Ada, as near as I can determine. In Ada publications it was traditional to highlight, by bold characters, all of the
keywords in the language. This notion continues today.

Highlighting, and in particular bolding, is intended to draw attention to things of interest. In normal prose one highlights portions of text that are under discussion, items of controversy, or famous quotes. The
technique is a primary tool of communication.

In computer languages, of which I have professionally coded in over 60, it is usually used in the Ada tradition of highlighting syntax.

Several objections can be raised. First, suppose we applied this to English. We could make the editor bold the 19 basic prepositions (at, after, by, down, for, from, in, of, on, over, past, round, since, through, till, to, under, up, with). While syntactically correct it is, to say the least, distracting.

This draws attention to these "keywords" in the sentence but, as a native speaker of English, adds nothing worthwhile. In computer languages this has the same effect. It is not at all useful to bold keywords like IF, THEN, or ELSE. Any native speaker of the language can see these at a glance. Bringing such "background" items to the "foreground" of attention highlights the static, inverting the usual
use of the technique in communication.

Even worse, some languages don't have "keywords" in the usual sense. In Lisp it is entirely possible to use the symbol "if" in any number of contexts, only one of which invokes its meaning as a conditional statement. It is a complete waste of cycles to dynamically re-parse
text that a native speaker can read.

Second, and worse, such highlighting undermines the most important aspect of the technique, namely to draw the reader's attention to something noteworthy. Bolding and other forms of highlighting are textual means of emphasis in communication. Regular, repeated, and non-communicative use removes this from the toolbox of the author.

Third, and on a personal aside, one often encounters color-coded program text in these highlighting schemes. As someone who is partially color blind it is often impossible to see some characters at all. It is usually possible to change these settings online but in
printed text whole passages are unreadable. Thus

  void foo(char *x) {
    if (x > b) then c else d;

in certain colors becomes

foo( x) (x b) c d

which, I must say, certainly de-emphasizes the language syntax though
losing a bit in semantics. :-)

So consider the difference between "coding for yourself" where your editor highlights code in pretty rainbow colors and "coding or writing for communication" where the techniques for directing the attention of
the audience matters.

BE BOLD! may work for a wiki but not for communication.

Tim Daly
The uncommunicative curmudgeon.

Axiom-developer mailing list

William Sit, Professor Emeritus
Mathematics, City College of New York
Office: R6/291D Tel: 212-650-5179
Home Page:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]