December 22, 2004
A Beautiful Language
I picked up one of my old computer science text books this holiday and started reading it. (Nothing like a good text book to unwind with as they say ;) ). The book in question is "Structure and Interpretation of Computer Programs" by Abelson, Sussman, and Sussman. It's a classic text written in 1984 and still used widely today (so I believe) to teach the art and science of programming in many university curriculums. The language it uses for this purpose is Scheme (a dialect of Lisp).
I know that I studied this book whilst at university (there are even some of my handwritten notes in the margins to prove it), but at that time what I mostly remember is learning enough about "cons," "car," and "cdr" to complete the programming assignments that went with the course. Reading it again now, after more that a decade of commercial programming in procedural languages, I'm completely struck by the beauty of the language and the approach.
For example, in the very first chapter is an elementary example of using procedures as parameters (a blurring of procedure and data). The procedure in question sums the values of some function f(x) across an interval from a to b, and takes as arguments the function itself, a, b, and another function 'next' that generates the next argument value. This is trivial to express in Lisp and fits completely naturally within the language. Lisp isn't the only language to let you do this of course. Ruby for example deeply integrates the concepts of blocks into the language. What's great about the Lisp version is that it requires no new syntax or special conventions, it just works, seamlessly. So well in fact that it makes an elementary example in the language.
Whereas the first chapter is about procedural abstraction, the second chapter is about data abstraction. Here you find another wonderful blurring of procedure and data with a demonstration that the most fundamental building block of data in Lisp, the pair, can in fact be implemented solely using procedures (and no data structures at all). This works because of another effortlessly natural thing Lisp allows you to do that Java doesn't :- return a procedure as the result of calling a procedure.
By only the fourth chapter, the reader is invited to construct an evaluator for the Lisp language (written in Lisp of course). Lisp has such a clean and simple syntax and semantics that this is a much easier task than it would be in many other languages. In fact there's a nice quote on the back of my edition of the book that reads as follows:
This book presents a unique conceptual introduction to programming intended to give readers command of the major techniques used to control the complexity of large software systems: building abstractions, establishing conventional interfaces, and establishing new descriptive languages.
If I look back over my programming career, I've built plenty of abstractions, and established many, many interfaces, but by comparison built very very few descriptive languages. This is probably for a combination of two reasons: one is that the languages I've been programming in don't make the establishment of a new descriptive language an easy and natural thing to do, and the second is that once you get out of the habit of using a certain technique, it tends to disappear from your toolbox after a while.
So at the end of the day, this is the thing that really impresses me about Lisp (and about the approach to teaching programming taken in the book). The language is so simple, and yet constructed in such an elegant way that it just doesn't get in your way - whatever abstraction you need to build, Lisp lets you do it in a very direct manner. Java just feels plain clunky when you put it alongside :- lacking in power, ease of expression, and beauty.
If I was to advise someone looking to go to university today to study computing, I'd recommend them to look for a place that first teaches programming using Lisp. Even though this is a less commercially attractive language than say Java, you'll learn much more directly the fundamental principles of programming. You'll then be able to apply these throughout your career in whatever language is flavour of the month (and no, it won't be Java forever more, you can be sure of that).
(1)Ok so, why am I reading a textbook on programming in Lisp? Do I read textbooks just for fun??? As you will have read above, Lisp makes the building of new languages a particularly easy task. This makes Lisp the language of choice for many text books and papers about programming language design and implementation. I like to study the foundational materials in any area in which I find myself working, and so given my role as lead of the AspectJ project, it makes sense to me to study Lisp for a season.
Posted by adrian at December 22, 2004 01:54 PM [permalink]
Adrian, I often come back to SICP - the best book on programming ever penned by the hand of man - myself. If you'd like to play with a version of Scheme that runs on top of the JVM and has a very clean interface to "native" Java checkout: http://sisc.sourceforge.net
I find it odd that the JCP guys are actually spending time on Groovy when SISC is there for the taking. To each his own I guess.
Posted by: Ward Harold at December 23, 2004 05:17 PM
If you want to play with Scheme in Java, I'd recommend jscheme - http://jscheme.sf.net. It's a pure Java implementation of Scheme that has a very clean syntax for using Java in Scheme - it's as easy as getting up and running with Jython, for example.
Posted by: shawn at December 30, 2004 03:31 PM
Since the comments above listed SISC and JScheme, I figured someone should mention Kawa as well:
It was my favorite Scheme-on-Java back when I made the JVM my primary platform (about four years ago; now I use native code compilers for Scheme). I don't know how its current version compares to SISC or JScheme, but it had a very nice infrastructure for generating Java bytecode at the time.
Posted by: pnkfelix at May 25, 2005 06:40 PM
Several months ago I found a gem-url:
Posted by: Andres at July 7, 2005 05:17 PM
Post a comment
Thanks for signing in, . Now you can comment. (sign out)(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)