Friday, February 29, 2008

Patterns of Software

Before I begin, I’d like to tell you that Neil Gaiman’s American Gods is available for a limited time free reading here. Gaiman had hosted a voting on his site before making this book available for free. The voters chose this one from among many of his books to be made available for download in this way. Please spread the link to as many as possible because a) as many as possible should read this absolutely awesome book and b) Gaiman seems to think that if this gets popular, more of his books may be made available for free which is a good thing.

Next on, read this article on the farce of reality shows by Pradip Somasundaran, the winner of India’s first music reality show Meri Awaaz Suno in which he won the Lata Mangeshkar award for the best singer along with none other than Sunidhi Chauhan.

Right, to get on with the actual subject matter of this post.

Today, after a long, long time, I started reading a book that got my brain machine running a like a factory. The book is called Patterns of Software and is written by Richard P. Gabriel. You can download the book here.

The book is essentially a collection of essays by Gabriel when he was the editor of the Journal of Object Oriented Programming from 1991 to 1993. They examine the issues involved with the philosophy of object oriented design in software. But the most remarkable thing about this book is that it examines object oriented design in the light of the ideas developed by the architect Christopher Alexander. Yes, you read it right, an architect.

The fundamental principle of Alexanders views is that building are inhabited by people – they are alive. He studied architecture from around the world and noticed that the most beautiful buildings were found in the countryside in Europe. He said that these buildings were beautiful because people inhabited them. What he meant was, that people owned these buildings, over time they made small alterations or changes to these buildings, they felt responsible for these buildings. Hence, a sort of harmony emerged out of this confluence of men and buildings that created beauty.

This, he said, is contrary to modern design principles in which buildings are constructed according to a master plan – something that someone sits down and decides once and for all - and the actual users of the building have little or no say in modifying the building to their own needs.

There are various aspects to this design philosophy of Alexander’s and the end result are design patterns – underlying process patterns that create beauty within a design.

Gabriel, in one stroke of genius takes up these principles and applies them to software design, and object-oriented design in particular. Gabriel is not unique in having ported Alexander’s ideas to software, many had already done by the time he wrote his essay. (And indeed other fields of design had freely borrowed from Alexander.) What is unique about Gabriel’s analysis is that instead of the end user, he defines the programmer as the ‘inhabitant’ of software.

This approach is clearly different from the wide spread view. Traditional and even contemporary (if indeed these terms can be used for a barely 40 year old industry) software design puts the end user to the fore. User’s needs are analysed and a master plan is drawn out. The programmer is then charged with the job of merely constructing this master plan – often with little or no freedom to modify the plan according to his needs. But, Gabriel argues, it is the programmer who is the real ‘inhabitant’ of software. Software development can often take years and it is the programmer who spends time with the actual code. The user merely sees the outer finish, the facade. Hence, programming practices should be programmer centric.

He then goes on to mesh, in steps, Alexander’s theory, with his own rich experience with software development and critiques practices that tend to alienate the programmer. The ideas are refreshingly new and to some might come as a surprise. For example, there is an old adage in programming – there is not problem that cannot be solved with another level of abstraction. Gabriel is against this kind of over-abstraction.

The book is making for a fascinating read. Gabriel doesn’t analyse open source development practices possibly because open source wasn’t a big thing back in the 1990s. But today I can see how open source people have knowingly or unknowingly picked up some of Alexander’s and Gabriel’s ideas and are therefore producing more programmer centric and hence better code. After all, the programmer is trying to produce code that does what the user wants – his needs are not any different that the user’s needs. However, unlike the user, it is the programmer who has to actually write all that code. Hence, software development should definitely be programmer centric.

This is precisely what open source does. They start off without a ‘master plan’ as such and keep modifying their program according to user demands as and when they arise. Besides, the user is allowed to inhabit the code too. The user can report bugs, write howto’s and contribute to the wiki. He is part of the software development process!

The ideas are rich and I might elaborate upon them one by one in subsequent posts. And whether I do or do not, you must definitely go and read this book.

No comments:

Post a Comment