Daniel Nouri's Old Blog

Note that this blog is discontinued. You can find my new blog here: Daniel Nouri's Blog.

Sun, 27 May 2007

Patterns, simplicity and simple patterns

Five Easy Pieces - Simple Python Non-Patterns from Alex Martelli was something that I had tagged toread for quite a while now, and it turned out to be a very interesting read.

The most important point that Martelli makes in this paper is that in Python, some of the traditional software design patterns don't apply, because the Python programmer has facilities that other OO languages lack, the lack of which makes certain patterns necessary in other languages that seem superfluous in Python.

It's nice how Martelli puts context into this topic, by explaining some of the background of patterns. Most notably, he references a book called A Pattern Language - Towns, Buildings, Construction by Christopher Alexander and a paper called The Structure of Pattern Languages by Nikos Salingaros, which is available online.

There's quite a nice analogy between software patterns and architectural design patterns. The dictionary of design patterns of Christopher Alexander lists examples for patterns found in architecture like SMALL PARKING LOTS, for which the summarizing statement is Vast parking lots wreck the land for people.

Interestingly, both Alexander and Salingaros are harsh critics of modern architecture. Salingaros writes:

Architecture has changed in this century from being a trade serving humanity with comfortable and useful structures, to an art that serves primarily as a vehicle for self-expression for the architect. In the current architectural paradigm, the emotional and physical comfort of the user are of only minor importance.

Well, this reminds me of software architects who care more about their design than users. The Big Design Up Front page in the PPR has some nice quotes and statements that go with this.

It makes sense to me when Martelli explains how some patterns are unnecessary in Python and others that tend to be involved in other languages are very easy in Python. Need a Singleton? Just create an instance of a class and have clients access that instance by its name. Need a registry? Make a module global instance of a list or dict, and have append and remove be your register and unregister functions. In Eby's article Python is not Java, one reads about a software project:

So, the sad thing is that these poor folks [a team of former Java developers who were new to Python] worked much, much harder than they needed to, in order to produce much more code than they needed to write, that then performs much more slowly than the equivalent idiomatic Python would.

Simplicity is the key to quality, and simple definitely beats complex. Test-first is probably a good way to create simple designs. The KISS principle represents:

If you have a choice between a simple solution and a complex one, then opting for complexity would be stupid.


All design should be as simple as possible, but no simpler. [...] the more elegant designs are usually the more simple ones. Simple also does not mean quick and dirty. In fact, it often takes a lot of thought and work over multiple iterations to simplify.

Python code is by nature simpler than code in many other languages, because it lets you focus on your actual problem -- making simplicity a built-in feature, and apparent that the source code is the design. Finally, a nice quote from Kent Beck found in the PPR:

As a consultant, 80% of the time my job involves taking out premature abstraction so we can get the damned thing out the door.

For me, the PPR is an enormous repository of insightful ideas about software development. I've already emptied my cup and I'm surfing for my next zen slap! :-)

posted at: 07:37 | 2 comments | category: /devel rss | permanent link | add to del.icio.us or digg it


Posted by Reinout van Rees at Mon May 28 13:34:40 2007
About that criticism of modern architecture: I partially agree and disagree. Of course, there's a load of architects that design "normal" buildings. the bad things start to happen once you have prestigious buildings.

Disagreement: what do the owners want? A medieval cathedral isn't the pinnacle of comfort, but it hits the sweet spot of majestic glory that was the aim of the owner. Whether the glory was that of God or the city that build it is question #2. Modern architecture can also have similar requirements.

It is way better when you build buildings that you have to sell/rent afterwards: then you really design for your users. A nice bit of background information is the threesome that's important for office space rentals: the 3 "L"s: Lobby, Lavatory, Lift. The rest is standard, but those three are the things people pay attention to.

Agreement: it was even the reason behind one of the 10 propositions for my PhD thesis defense: "The library of TU Delft and the architecture department of Eindhoven university have a stair with steps that have the un-ergonomic length of 1.5 stride. The fact that the architecture department has such a stair does not help to prevent said mishap in the future." So some architect added a stair that violates every human-anatomy-oriented design principle "as it fits better in his design" or "helps you to give your full attention to the building". Aargh. 80% of the TUDelft students want to publicly execute the architect of the library.

... but the TUDelft as an organisation is happy with the library as it even attracts tourists on Delft's architecture tour. Yuck. I think the building would have been just as great with a reasonable stair...
Posted by Ed M at Wed May 30 05:18:31 2007
What is most interesting about Christopher Alexander's influence on computer science is that he did not intend to create the "design pattern" movement in computer science as he notes in the forward to the tenth anniversary edition of the book "Notes on the Synthesis of Form".  And he actually apologizes for accidentally doing it.

I was introduced to Alexander's work while talking to a O'Reilly editor about architecture, planning and the web.  He had mentioned that Alexanders work had a great influence in the Computer Science field. After our conversations I got a hold of a couples of his other books including "The Pattern Language".  While reading through "The Pattern Language" I started to wander how his writing made it's way into computer science.

It wasn't until I read that tenth anniversary edition of "Notes on the Synthesis of Form" did I start to see the complete picture.  It is almost funny the series of events that lead to what we now talk about. Alexander was trying to formulate some ideas (which would eventually become the book "A Pattern Language" along with another individual (whose name I can't remember).  This formulation expressed in the book "Notes on the Synthesis of Form" was all mathematically based. There is formulas, equations, etc even if I recall correctly graph theory. All the standard mathematical language trying to describe in this case patterns in community planning.

Why I say this is all laughable because reading "A Pattern Language" then reading "Notes on the Synthesis of Form" and Alexander's revisited forward you see all these unintentional influences. I highly recommend you get a copy of the tenth anneversary copy of "Notes on the Synthesis of Form" and read it, along with " A Pattern Language".

Comments have been closed

< May 2007 >
   1 2 3 4 5
6 7 8 9101112

Feed of all categories: rss rss | atom