gnuvince’s law of programming discussion

April 20, 2009

The amount of discussion a programming topic generates is inversely proportional to its importance.


On programming language design

April 12, 2009

Andrej Bauer has a very nice article about language design on his blog, which happens to reflect a lot of what I believe about programming languages myself. Highly suggested.

“Programmers are just humans: forgetful, lazy, and make every mistake imaginable.”


Response to the prefix syntax “debate”

April 9, 2009

In a recent blog post, Brian Carper came out in defense of Lisp’s unusual syntax citing regularity and ease of manipulation (by humans and computer programs). The response in the comments and on Reddit were mixed with many people — myself included — echoing Brian’s sentiment and as many people voicing their distaste for Lisp’s syntax.

A common criticism put forth by opponent of prefix syntax is that it makes maths “unnatural”. They write formulaes in infix and prefix styles and expect the reader to see how much clearer and natural and intuitive infix is. Here’s an example taken from a comment:

1 + 2*f(x,y) + 3*g(x)

vs.

(+ 1 (* 2 (f x y)) (* 3 (g x)))

Of course, most Lisp programmers would probably prefer to break down the prefix version into multiple lines to show the structure of the expression more clearly:

(+ 1
   (* 2 (f x y))
   (* 3 (g x)))

The “problem” with this solution was that it was now on three lines and apparently, it was “66% less productive” than the equivalent infix representation. I have my doubts on this claim. :)

However, if you thrown in comparison, boolean and bit operators, now your can have some fun. Quick, parenthesize the following expression without looking up your C reference: 1 & 2 * 3 || 4 + 5 ^ 6 < 7 - 8 == 9.

Regardless of how one feels about whether infix operators are more natural, it doesn’t really matter, because most of us don’t write programs with a lot of long mathematical expressions. In fact, I’d bet that the vast majority of arithmetic operations are adding 1 or subtracting 1 from a value. Hardly worthy of a debate.

Functions are used a lot more than operators, and in all mainstream languages they have the prefix form and nobody seems too stumped by them. Why is that? And if you aren’t stumped by prefix syntax, wouldn’t you like it if it was the same for every operation so that your code was effectively a tree that you could manipulate at compile-time with macros to add your own syntax and extensions to the language? Surely you would!