The aesthetics of syntactic sugar

September 26, 2008

The Unix test program makes for a great illustration of the aesthetic importance of syntactic sugar, to go along with its pragmatic effects. Consider the following two shell script lines:

if test -f /some/file; then ...
if [ -f /some/file ]; then ...

In any Bourne shell environment worth its name, these two have exactly the same results and in fact run exactly the same program (or an imitation of it), because [ is just another name for test. But at least to me, they read significantly differently, and I find that the second one looks better and reads more clearly.

(I think the problem with the first one is that everything looks the same, because it's all words and switches. In the second one, the [ and ] stand out visually and so act as useful punctuation.)

To go out on a limb, I think that this is one of the drawbacks of languages like Lisp. By having no syntax they also have no syntactic aesthetics, whether bad (all too common) or good; instead, everything disappears into an even flow of words and parentheses. There are virtues to this regularity, but I can't help but think that such languages are missing something too.

(Possibly the answer for syntax-less languages are IDEs that add in 'punctuation' in the form of colour, different fonts, and so on.)

Comments on this page:

From at 2008-09-26 06:31:05:

I personally don't miss the features of infix languages. The regularity if Lisp's syntax means, for instance, that there are no operator precedence rules which cause complex expressions in C to become either "verbose" by adding superflous parens(sometimes more than in the equivalent Lisp expression) or very difficult to parse unless you know by heart all levels of operator precedence.

If you ask any experienced Lisp programmer how they read Lisp code, you'll always receive this answer: after a while you get used to the parentheses and you ignore them, reading code instead in terms if words and geometric patterns: IF has its pattern, COND a different one, WHEN too, et cætera ... Going from one style to the other requires time to adapt and different mental skills.
Perhaps it's similar to how it's been noticed that reading alphabetic and ideographic scripts engages different parts of the cortex: it has been observered in sino- and nippo-americans that being dyslexic in reading English didn't influence the capacity of reading ideograms and vice-versa.

From at 2008-09-26 07:58:10:

I prefer regularity over syntactic verbosity. for e.g tcl

if [mytest] {
} {

is way more easier to read compared to the ones quoted above because there are no special cases (every thing is a command.) and ambiguities.

From at 2008-09-26 10:43:53:

To go out on a limb, I think that this is one of the drawbacks of languages like Lisp. By having no syntax they also have no syntactic aesthetics

So you'd say the same thing about python, I presume?

From at 2008-09-26 13:12:48:

Although certainly not as complex as C's, python has syntax(sugar).

From at 2008-09-26 21:38:25:

Actually I'd argue that python has less syntax sugar than lisp, at least with lisp most editors can easily be informed of how to move up or down a "block". Or from the begining to the end of the conditional in an if (this is possible in python if you treat multiline conditionals as evil, or always wrap them in parens).

The fact is wants you to write "if foo and bar:" practically guarantees I need a high level syntax highlighting editor, and while that's almost a must in lisp to edit reading doesn't require one.

Hell python is the only language I use where I can't just cut and paste code and hit tab a bunch of times to re-indent it at it's current level (probably the biggest annoyance I have with it's lack of syntax, but far from the only one).

Written on 26 September 2008.
« Why qmail is no longer a suitable Internet MTA
The problem with initial ramdisks »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Fri Sep 26 00:28:22 2008
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.