Why I Like Lisp

Posted on December 1, 2009

Uniformity

I’m tired of quirky syntax rules, operator precedence, and programming style guides. I hate wasting time thinking about the formatting of my source code. Some people are obsessive-compulsive about this aspect of the craft of programming. Some mistake it for “beauty” when they read program source. But syntax and formatting are tedious and boring details that only frustrate and annoy when they get in the way.

Lisp makes my life easier. It has an extremely… symmetrical syntax (is that the right word?). All those parentheses that annoy some programmers are actually what makes working with Lisp such a breeze as far as managing the syntax and formatting of source code. My editor can treat Lisp code as data structures it can manipulate and thus take care of the formatting and syntax in a uniform and deterministic way. I don’t have to think about it. That leaves me more brain room for thinking about programming.

But all those parentheses!

If this is your major complaint, I have an exercise for you: using a decent source-code editor like emacs, load up some Lisp code and modify the syntax highlighting to change the color of the parentheses to the background color (or maybe just a few shades shy of the background color). The parentheses are still there, but you don’t have to pay attention to them. Any decent editor will automatically balance them for you and format your source code so that it is legible. No need to nit-pick about spaces, commas, delimiters, infix operators, precedence, and the slew of other problems that infix notations and delimited-statement languages present. None of it.

Abstraction

I’m not even an intermediate Lisp programmer yet, but just reading about and seeing examples of macros was really enlightening. I can’t even count the number of lines of Python code I had to refactor over the last few years simply because the same patterns keep appearing in my programs. I keep getting repetitive boilerplate code, refactor it out, and move on; the cycle continues until I feel like I’m done — but it always feels like I’m sweeping dirt under the rug. Well six rugs actually and some rugs only act as interfaces to the other rugs. Macros on the other hand allow me to remove boilerplate code up front without creating another layer of indirection. They also have the pleasant side effect of becoming an embedded domain-specific language for my program.

Probably more important and fundamental than macros are symbols! The ultimate abstraction. A symbol can be used to identify nearly anything in Lisp whether its a value or some function. They’re kind of like how symbols work in mathematical notation and are just as useful in expressing our thoughts clearly.

Expressiveness

Well written Lisp programs do more than describe the mechanical implementation of a solution. Those details are hidden behind a high-level language that can be reasoned about independent of the computer. The verbs, nouns, and grammar are not bound to the machine or compiler that reads them. The programmer is free to add, redefine, and supplement the language to suit the problem. When a Lisp program nears completion, it begins to read more like a description of how to solve the problem rather than how to tell a computer how to solve the problem. Find some good Lisp code, download it, read it. It’s a rather pleasant experience and easier than it seems at first.