Sunday, June 15, 2008

Lisp

My latest thing is lisp. I tried picking it up about six months ago. I read part of Practical Common Lisp, and implemented some of their examples, but I didn't really get the point, and the fact that it was a whole different platform from the JVM turned me off. After all, what good is syntactic sorcery if I can't have my favorite libraries? No good.
But I a week or two ago I was reading Ola Bini's blog and he mentioned a dialect of lisp on the JVM called Clojure. I decided to try and learn it; which for me means using it in a project. So far I'm not quite sure if I like it. It's totally non object oriented. The guy who created it specifically stated that he thought OOP was the wrong way to go, and that pure functional programming was much better. Having no objects has thrown my code-sense off track. I'm finding it difficult to judge whether my code is good or not.
What's been nice though is the whole syntactic abstraction thing. It's shockingly easy to do metaprogramming in lisp. That's part of what I had been reading about it: that it was the original dynamically typed, garbage collected , dsl friendly and metaprogrammable language. That's pretty amazing considering it's over forty years old. Java, which is the language I associate with garbage collection, only came out like fifteen years ago. And languages that offer strong metaprogramming and dsl support like ruby and python seem only to have become popular in the last few years. Maybe lisp was just way way way ahead of its time, and still is.
I admit it was hard to get past the parenthesis at first. They honestly just don't look good. But they stopped bothering me after I spent some time with the language. I think that happens with just about any weird syntactic feature of a language: you get over it and stop seeing it as soon as you are used to the language. Essentially, besides overcoming the parenthesis, I've just been exploring the features. Clojure is interesting not just for being a lisp dialect, but for it's strong concurrency support. That's probably going to be its selling point if it ever gets wide adoption. I think it's probably unlikely to see too much light though, since though everybody admits lisp is the ultimate language, they all seem to think that it's utterly impractical for the typical programmer. Personally I think the malleable syntax is great; it's just the absence of objects that gets me. How am I going to structure my programs? Where are the nouns? How do I group functions together? I'm sure I just need to find some more material on how to do functional programming right.
Anyway, I like this whole notion of polyglot programming: that different languages can serve distinct purposes in a single program. I'd imagine you'd want to use Clojure to handle concurrency, with all its STM magic, and something like python or ruby to do the business logic (at least then you can have objects.... sheesh). What's most certainly the case is that though you'd want to be running on the JVM to get all those hot libraries, you'd certainly not want to be programming in Java.

0 comments: