Sunday, June 27, 2010

Walk a mile in a Lisp hacker's moccasins

"What's so great about YOUR programming language"? Bob asked Alice. Alice had been here before, she knew that if you are asked that question you should not answer, it's a trap! What Bob's question really meant is "I am OK coasting with the language I already know, you are trying to persuade me to do what seems to be unnecessary work to learn your new-fangled  language". Thinking quickly on his feet he came up with this trick question, which really means "in 30 seconds or less convince me that the language is superior to the one I already know or perfect for my needs". As with any nuanced argument, the case for a particular language cannot really be made in a pithy sentence that has high sound-bite value. In life there are pros and cons for any course of action.

Bob had succumbed to confirmation bias, for whatever reason (I would guess laziness) he had already decided that he was not going to learn the language. What he was really looking for was an excuse. So he posed a question of the form "give me the one killer reason to do it", since there is no ONE magic reason, Alice would fail to provide it and he could live on blissfully and effortlessly too! Alice did not take the bait  though. Instead she offered to teach Bob the basics of the language, little by little through progressively more interesting examples. She followed through on her offer and bit by bit time Bob began to see where her passion for the language stemmed from. At the end of it he was not quite ready to jump ship but he felt enriched by the experience he had a great time and learned a new language in the process.

You can substitute my name for Bob, (though indirectly) Hal Abelson and Gerry Sussman for Alice and Lisp is the unnamed language in the little story above. For long time and for no reason that I can think of other than that the nested braces where a little hard to read I had long resisted learning Lisp despite much cajoling from one or two friends. I had my little reasons like Polish notation arithmetic was hard to read and a host of others. Then one day I came across Abelson and Sussman's recordings from 1986 of the MIT course Structure and Interpretation of Computer Programs (SICP). That chance happening changed my view of Lisp completely in less than two weeks. SICP was taught in Scheme a dialect of Lisp, it took a few attempts but I eventually got into it, watched the videos attentively and was rewarded handsomely.

There are 10 lectures and by the end of the 5th one, having written with ridiculously little effort a host of interesting programs and in the process creating both an embedded an interpreted Domain Specific Language, I was a changed man! I had seen the light, I finally understood the ravings which just a fortnight earlier were incomprehensible.  My eyes no longer blind to the light I realised that similar derisions to those made against Lisp can and have been made against other languages like say Python1 of which I am a great fan. So I whole heartedly encourage you watch the lectures or read the book which is available free on-line. After the first few chapters you may not be rushing to write your next web application in Lisp but I guarantee you will have a much better appreciation of the virtues of Lisp. The Native American prayer really rings true here: Grant that I may not criticize my neighbour until I have walked a mile in his moccasins. What's more with Lisp you need not even walk the full mile, a few hundred yards will do.

1. No curly braces? You rely on indentation to indicate block structure? That is crazy talk!

Sunday, June 13, 2010

Trapped on a local maximum

A few months ago my laptop died and after several futile attempts to resurrect it1 I finally let it go. So I purchased a new laptop, restored my data from the old one and proceeded to get it set up just the way I like it. This was going to be a long but enjoyable process. Finally though the Yak Shaving had to come to an end I had a project to get working on. It was a web project and I was going to use my de-facto choice, Python and TurboGears, but then I thought maybe I should reconsider my tool-kit. I never really considered using a language other than Python but on the web framework choice there was room to manoeuvre, or so I thought.

I was in a hurry, I had a project to get started on and the laptop saga had set me back significantly. So I decided to take a look at what many would consider the market leader in Python web frameworks: Django. No sooner than I had started going through the tutorial I was longing for TurboGears. I told myself that it might be worth it, the Django project seemed more active, the documentation significantly more complete and so on. As time was of the essence and motivation to learn something new lacking, I started my long overdue project using TurboGears and I was as happy as a Duck in water.

My reluctance to even take the time to learn another web framework got me thinking, what is it about TurboGears that I like so much? Sure I like the extra power SQLAlchemy brings to the party but other than that, in terms of fitness for purpose these web frameworks are pretty comparable. I came to the conclusion that TurboGears was just comfortingly familiar to me, not in a deep meaningful way, but rather in the most superficial way imaginable.

My programming experience until a few years ago was mainly with the the C family of languages with the majority of my professional programming life spent using Java and Java Enterprise Edition. When I thought about things in that context I realised I just wanted to stay true to the Java annotation and XML values instilled in me from my Java and JEE heritage. I just like the way TurboGears code looks, the @expose decorators remind me of Java annotations and the XML based templating engine reminds me of well... all those XML documents you have to create in a JEE application.

When I started using Python and TurboGears I think I subconsciously gravitated to what looked familiar. So even though I had taken the plunge and started using a dynamically typed language, perhaps I was trapped on a local maximum! Looking back over my code I was relieved to find that this is not the case. I write Python code in Python not Java code using Python syntax. It is funny though that I still and probably always will find @ symbols and angled brackets beautiful.

Update: August 2010
The internet allows us to collaborate with and befriend people in remote places, but I have always been a believer in meeting people face to face when ever possible. A few weeks ago I went to PyCon Ireland there I attended the Introduction to Django tutorial by Michael Twomey, it was a slightly informal walk through the basics of Django and some more advanced and very useful bits and bobs. Since then I have been able to work through the Django tutorial with much more success than before. A little bit of in person hand holding was all it took to get past the inertia that was holding me back.

1. Including foolishly replacing the motherboard which extended its life by about 6 weeks, instead of spending that €250 on maxing out a replacement.