The Business Value of Beauty (in code)
posted by Alex at 08/07/10 04:50 PM
One of the more distinctive aspects of the ruby language is it's aesthetic elegance. Most would agree that so far as programming languages go, ruby is a beautiful language.
At first glance, this might suggest that this so-called beauty is purely aesthetic, surface-level, and provides no real intrinsic value. This led me to hit the 'tubes and find a definition proper for the word beauty:
the quality present in a thing or person that gives intense pleasure or deep satisfaction to the mind, whether arising from sensory manifestations (as shape, color, sound, etc.), a meaningful design or pattern, or something else (as a personality in which high spiritual qualities are manifest). source
To my surprise, this definition jives quite nicely with what has been floating around in my head as beauty relates to code. The gist of those thoughts are that beautiful code makes my brain smile. It puts my brain at ease, because reading beautiful code is much, much easier than reading ugly code. Seems obvious, I know, but I've read enough ugly code to know that many programmers simply don't see the value in crafting beautiful code.
But the title of this post name-drops "business value", so where's the beef?? At this point I should clearly define what I mean by "business value". Put simply, it is that which can be measured, in some form or another (there are many other ways that beautiful code is valuable but not easily quantifiable).
Maintainability FTW
That said, the business value in the beauty of code is maintainability. The more beautiful a given piece of code, the less energy someone else exerts in trying to interpret the utility of said code, and thus, fewer resources (whether measured in time, money, man-hours, brain-power, focus) are exerted in the process of refactoring that code.
So what exactly makes a given piece of code beautiful? Following SOLID design principles in how you choose to design your code, communicative method and variable names, and following ruby conventions. The key reason these things are important as they relate to beauty and business value in code is communication. A good litmus test is simply to ask whether a piece of code clearly communicates its own intent.
In-code Communication
Communication in code is important. Reading other people's code, in my opinion, is one of the harder things to do in programming. If someone else's code is by some judgement, beautiful, this quality also communicates some level of intent of the author. Some care must be taken by the author to create code that is both meaningful and beautiful.
There are also some other side-effects of beautiful code to programmer productivity, though maybe not as quantifiable. One such side-effect is programmer happiness.
I remember quite vividly the first time I read through the sinatra source code. It is such a thoroughly-crafted piece of code, and from a consumer's perspective, it is so easy to understand what's happening. I promise you, this is not by accident. When I read code like this, it makes me happy, and it inspires me to write my own code similarly beautiful. And a happy programmer is a productive programmer.
Homework
So go read some beautiful code, and create some of your own ;) If you're anxious for a good starting point, I highly recommend sinatra. What open source projects do you find to be beautiful? We're anxiously awaiting your suggestions in the comments :-)
