Sunday 28 February 2010

Good looking code

Some programmers have the strange idea that if programming is a science or even a branch of engineering, then there should be no room for aesthetics. In my experience, the best programmers always care about aesthetics: beautiful code is effective, maintainable code. Refactoring code to make it look better removes bugs.

Python...
Like many programmers who have the choice, I chose my main programming language because it feels good. After several years of Perl-ing, Python has been a lovely language to use.

One constant surprise, after 20 years of programming, has been the high quality of the design of standard python modules. You can fix the innards of your library but mistakes in the public interface stay forever, unless you are prepared to piss off half your users by breaking their code. The quality of python libraries is a good sign the python community cares, and this is the best reflection of the language itself.

.. vs C++
Lately for performance as well as professional reasons, I have turning back to my first love, c++. Admittedly, c++ syntax appears full of unnecessary warts, ... if you are in the business of inventing a language from scratch. I haven't heard anybody talk about the beauty of the c++ language. Nevertheless, programming intensively in c++ again after a little break has been a forgotten pleasure.

It is a different aesthetic: the hunt for lean mean code, to write logic at a high level which can nevertheless be compiled down to the fastest executable imaginable. I can remember poring over Stephanov's STL in 1996, knowing that this would be game-changer for c++, and being astounded by Veldhuizen's Blitz++. This is the raison d'ĂȘtre of c++.

Back to aesthetics
This has reminded me that each programming community brings its own appreciation of attractive code. Most languages have to start off by attracting a core of enthusiasts, persuading them that programming in XXX is more fun as well as more effective than what they are using now. There is no point in inventing another ugly, painful language, however useful it might be. We have more than enough kludges, thank you very much.

Scala, Clojure and Google Go each has its own aesthetic which is happily defended with much vigour by their inventors and community. The resulting buzz means that they are accordingly much more likely to have significant communities in 10 or 20 years time. Is this where we should be putting our money? Time will tell.

No comments:

Post a Comment