What Are Some Quality Properties of Computer Language Syntax?

Perm url with updates: http://xahlee.org/comp/properties_of_syntaxt.html

What Are Some Quality Properties of Computer Language Syntax?

Xah Lee, 2008-07, 2011-01

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

Here are some concrete examples of what i mean by 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 “#”. Note that this does not allow nested comment. So for example, if you have multi-line code, and you want to comment out them all, you have to pre-pend each line by the comment char. However, if you have block comment syntax, one could just bracket the block of code to comment it out.

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. Similarly, in javascript for example, ending semicolon is optional when it is at end of a line.

In Mathematica, the language has a syntax system such that you can use fully regular nested notation (e.g. f[g[x]]), postfix notation (e.g. x//g//f), prefix notation (e.g. f@g@x), infix notation (e.g. 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: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations)

In general, a computer lang has a syntax. The syntax, as text written from left to right, has various properties and characteristics. Ease of input (think of APL as counter example), succinctness (e.g. Perl, APL), variability (Perl, Mathematica), readability (Python), familiarity (C, Java, Javascript, ...), 2-dimensional notation (e.g. traditional math notation) (Mathematica), ease of parsing (lisp), regularity (APL, Mathematica, Lisp, XML), flexibility (Mathematica)... 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, etc, 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 char set.

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs