What Are Good Qualities of Computer Language Syntax?

, ,

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.

In many languages, such as Perl, they have comment syntax of a special char running to end of line. For example, in Perl, Python, Ruby, Bash, Windows Powershell, the special char is #. So for example, if you want to comment out multiple lines of code, you have to move cursor to the beginning of each line to add the comment char. However, if you have block comment syntax, one just need to type at 2 positions: the beginning and end of the block.

Of course, these langs may also have block comment syntax, and even if not, programing text editors often have features to add the comment char to a block of lines. However, 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, the formatting 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.

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.)

In Mathematica, the language has a syntax system such that you can use fully regular nested notation (⁖ f[g[x]]), postfix notation (⁖ x//g//f), prefix notation (⁖ f@g@x), infix notation (⁖ 1~Plus~2 instead of Plus[1,2]), for ANY function in the language, and you can mix all of the above. (prefix and postfix by nature are limited to functions with just 1 arg, and infix notation by nature are limited to functions with 2 args) This is a example of power of syntax. (For detail, see: Concepts & Confusions of {Prefix, Infix, Postfix, Fully Nested} Notations)

In general, a computer lang has a syntax. The syntax, as characters arranged in sequence from left to right, has various properties and characteristics. Ease of input (think of APL as counter example), succinctness (⁖ Perl, APL), variability (Perl, Mathematica), readability (Python), familiarity (C, Java, …), 2-dimensional notation (⁖ traditional math notation) (Mathematica), ease of parsing (lisp), regularity (APL, Mathematica, Lisp, XML), flexibility (Mathematica, Perl)….

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.

blog comments powered by Disqus