Tim\'s picture      Blogging Ottinger (tim)

2005-September-28

Design Sense and Aesthetic Sense

Filed under: Programming

Take OAOO (Once and Only Once), for instance. It seems obvious enough, but almost any code you find laying about is aswim in copied or retyped idioms. Is OAOO claptrap or good sense? Is it just XP craziness?

OAOO has received treatment under other names like DRY and SPOT (Single Point of Truth). It even gets a solid mention under Third Normal Form.

One could argue that it is a purely aesthetic issue, that it seems to suit some person’s sense of “good” or “right”, rather than actually serving a team’s use of the code. You hear the same argument about OO and Structured Programming (in particular, single entry/single exit programming). Indeed, every software discipline is attacked as “preference”. In the sense that it is possible to write code without using any discipline at all, I suppose one could say that writing clean, working code is a preference.

On the other hand, single-entry/single-exit helps with debugging and tracing, since you know that a debugging message or breakpoint set just before the return will be hit on the way out. It also helps with cleanup of resources (though try/finally is better and RAII works in C++). It has been a useful discipline for many years, partly for these reasons and partly for more mathematically-driven reasons (See Dahl, Dijkstra, & Hoare).

Likewise, there are perfectly good reasons to follow OAOO/SPOT/DRY in code. Most important is the principle that you want a single point of maintenance. This is why it is better to have a single implementation of Stack (in templates or generics) than to have a dozen implementations, hand-written for each type that might appear in a stack (int, double, string, structs, classes). The more similar code is repeated, the more maintenance points one has per function point. This is far more than a matter of preference or aesthetic. It is a matter of making code that can survive continued change gracefully or making code to which every modification becomes a tedious search and replace operation. It’s a matter of finding points of usage with grep or searching with human eyes for every repetition of an idiom.

Let us ignore the evidence for a second. If it were merely a matter of aesthetics, would you rather write code that the industry finds appealing, or that the industry finds revolting? Shouldn’t code be something you can enter into easily (well, as easily as possible)? Shouldn’t your peers find it simple and clean? Should the people who pay for the code be pleased with they code they receive? If the aesthetic is generally agreed-upon, perhaps the default stance should be to follow it until you have evidence that you have a more excellent way, rather than rejecting it out-of-hand.

Comments »

The URI to TrackBack this entry is: http://tottinge.blogsome.com/2005/09/28/design-sense-and-aesthetic-sense/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome | Theme designs available here