![]() |
Site Archive (Complete) | |||
|
ABOUT US |
CONTACT |
ADVERTISE |
SUBSCRIBE |
SOURCE CODE |
CURRENT PRINT ISSUE |
NEWSLETTERS
|
RESOURCES
|
BLOGS
|
PODCASTS
|
CAREERS
|
||||
August 09, 2005
Beautiful CodeMatthew Heusser
When was the last time you looked at a program listing and said "Now that's some fine looking code"?
How many times have you heard something to the effect of "Now that's beautiful piece of work?" I heard it often when I was an undergraduate. In fact, I distinctly remember Dr. Homer Austin using a phrase like that to describe the Fibonacci sequence.
After graduation I became a computer programmer, not a mathematician. With that, the word "beautiful" dropped from my professional use, if not from my professional vocabulary entirely. Still, one thing that was made very clear to me in school was that beautiful solutions were good solutions. Applying that to software development begs the question--what is "beautiful code"?
Someone might suggest that commercially successful code is beautiful, but that doesn't really help much--a "killer app" might be a great app, but its code could be ugly. Many code programs contain comments along the lines of 'here be dragons', and the expression "Don't touch fooboggle, it's huge, it's ugly, but it works" is no rarity. These functions may work, but they aren't beautiful--all we have identified is the absence of software goodness. This makes me wonder: What elements of "beauty" is all that bad code missing? If that code were different, how would it be different to beautiful? What does beautiful code have that bad code does not? After some thought, I've come up with a few things that I have consistently seen in code that I would call beautiful:
I am not suggesting that this is a complete list on how to make beautiful software; it is just a start, a jumping-off point. I think it makes a point: Instead of searching for some automated measure of our codes efficiency in (lines of code)/function points + (1/defect density) blah blah blah perhaps we should be striving for beauty in our work because we believe that beautiful things are better. Perhaps we should be building and weighing our own list of what makes beautiful code. In fact, you could submit that beautiful code should fail gracefully, or Design-By-Contract , or have a unity of design, or a dozen other things. Even without conclusion, the very discussion is healthy.
Why should we study software beauty? Well, think about the list above. Beautiful code tends to be smaller--so we can write more powerful software in less time. It tends to be testable, so we can improve it's quality and more confidently maintain it. Because it does one thing and is well-separated, beautiful code lends itself to re-use, which results in still more functionality delivered in still less time. In short, beautiful code is good code. If we write more beautiful code, we will be better programmers. When people try to compare personal improvement in art to improvement in software, that's about the best I can come up with.
The good news about code beauty is that it is a space that hasn't been explored much; there is plenty of room for us to make our mark on the body of knowledge.
AcknowledgementsRonald Jeffries, Andy Lester, Dr. Paul Jorgensen, Scott Kiwilski, and Chuck Dreyer contributed to this article.
Matthew Heusser is Technical Project Manager at Priority Health, where he manages in-house, integration, and outsourced software projects. He can be contacted at mheusser@charter.net.
|
|
||||||||||||||||||||||||||
|
|