What Are Good Qualities of Computer Language Syntax?

By Xah Lee. Date: . Last updated: .

You say that lisp syntax irregularities “reduce such syntax's power”. What you mean by “syntax's power”?

Here are some concrete examples of power of syntax.

Suppose you want to comment out 100 lines in a file. In {Perl, Python, Ruby, PowerShell, Bash}, you have to add the character # to the beginning of every line. However, if you have block comment syntax, you only need to insert at 2 positions: the beginning and end of the block.

Of course, programing text editors often have features to add the comment char to a block of lines in just a few keystrokes. But, in the context of analyzing a particular syntax, the line based comment syntax is inferior to block based one with respect to what the syntax can do. This, is a simple, perhaps trivial, example of “power of a syntax”.

In Python, code indentation is part of the lang's syntax. Some programers may not like it, but it is well accepted that Python code is very easy to read, and it has much done away about programer preferences and argument about code formatting. This is example of power of a syntax. 〔➤see Syntax Design: Python's Indentation vs Nesting

Let me give another, different example. In Perl, often the function's arguments do not necessarily need to have a paren around it. For example, print (3); and print 3; are the same thing. This is a example of power of syntax, with respect to reducing the effort to type. Similarly, in JavaScript for example, ending semicolon is mostly optional when it is at end of a line. (this JavaScript syntax feature causes other problems, but, still, with respect to saving keystroke, it is a positive point when done right. 〔➤see JavaScript: Semicolon〕)

In Wolfram Language, the language has a systematic syntax. For example, you defined a function “add1” that adds 1 to a number. You can call it by function notation add1[n], or postfix notation n//add1, or prefix notation add1@n. All these syntax can be used for ANY function, buildin or user-defined, and can be freely mixed. This is a example of power of syntax, with respect to flexibility. 〔➤see Concepts and Confusions of Prefix, Infix, Postfix and Lisp Notations

In general, a computer lang has a syntax. The syntax, as characters arranged in sequence from left to right, has various characteristics and properties. Ease of input (think of APL as counter example. 〔➤see APL Symbols Meaning and Code Example〕 ), succinctness (For example, Perl, APL), flexibility (Perl, Wolfram Language), readability (Python), familiarity (C, Java), 2-dimensional rendering of code (Wolfram Language, TeX), ease of parsing (lisp), regularity (APL, Mathematica, Lisp, XML), etc.

Basically, you can look at syntax, and programer's need to type them, and how the textual structure can be mapped to the semantic space, from many perspectives. The good qualities, such as ease of input, ease of reading, ease of parsing, ease of transformation, simplicity, flexibility, …, can be considered as elements of the syntax's power.

As a example of syntax of little power, think of a lang using just the symbol “0” and “1” as its sole charset. (machine language has that syntax.) In such a language, it would be unsurpassed in simplicity, but inferior in any other aspect of syntax.