Syntactic Sugar and Salt

By Deane Barker on July 26, 2006

Syntactic sugar: I had heard this phrase quite a bit, but was never quite sure of the meaning. I had a hunch (and it turns out that it was right), but this is still an interesting discussion.

Syntactic sugar gives the programmer (designer, in the case of specification computer languages) an alternative way of coding (specifying) that is more practical, either by being more succinct or more like some familiar notation. It does not affect the expressiveness of the formalism.

Ruby is full of syntactic sugar. Even more interesting, however, is the discussion of “syntactic salt”:

[…] a hoop the programmer must jump through just to prove that he knows what’s going on, rather than to express a program action. Some programmers consider required type declarations to be syntactic salt. A requirement to write “end if”, “end while”, “end do”, etc. to terminate the last block controlled by a control construct (as opposed to just “end”) is widely considered syntactic salt.