What is Beautiful Code?

January 8, 2010

The book Beautiful Code has sparked a variety of opinions. A couple of critical observations about the book:

It has a variety of authors, and the book comes across as a collection of independent essays, with each chapter standing on its own.

More often than not, there is no real discussion from the authors about what beautiful code really means to them.

I thought about my own definition of beautiful code and decided to solicit the opinions of others on LinkedIn to see if they shared my opinion. I received some great responses, and let me once again thank everyone who did respond. The majority of the respondents felt (as I do) that beautiful code is something that can be easily maintained over time, and not something expressed in an "artful" way that requires study for a period of time to appreciate its beauty – and to understand its function. There is a definite difference between was is desired in the working world and what would be acceptable as “art” in other settings.

In particular, I’d like to expand upon (and slightly modify) one response from Bidyut Raj, who provided a truly great analogy.

Beautiful code is like a diamond.

The diamond metaphor defines beautiful code and explains why beautiful code is more valuable than ugly code. The analogy covers the 4 C’s of a diamond as well as the setting of the diamond. Consider the following in terms of both the definition and value of beautiful code.

Clarity describes the purity of a diamond, and is determined by the number, size, and location of imperfections. The fewer imperfections that a diamond contains, the more beautiful the diamond is.

Ergo, beautiful code should not contain imperfections, whether these imperfections are design flaws, bugs that lead to problems during execution, or even the use of confusing, inconsistent coding standards.

The best color for a diamond is no color at all. A totally colorless diamond allows light to pass through it easily.

The interfaces of beautiful code should be intuitive, simple, and easy to use, whether the interfaces are programming interfaces that another programmer invokes or the user interface that customers utilize to interact with the software. Beautiful code should be completely readable (by humans) to the extent that the code is literally self-documenting and something that can be easily maintained over time by others. The expression of logic should be precise and understandable, which means that the code should not contain arcane tricks that can take an extraordinary amount of time for someone else to decipher.

Cut refers to the proportions, finish, symmetry, and polish of the diamond, factors that determine the fire and brilliance of a diamond.

Beautiful code should have a design and implementation that meets the functional and non-functional requirements to such a degree that anyone looking at the code recognizes the brilliance in the craftsmanship of the code. Like diamonds, this is difficult to quantitatively judge, but a great “cutter” (programmer) can significantly influence the value of the code, and can even transform existing, ugly code into beautiful code.

The carat is the unit of weight for a diamond, with value increasing with carat size.

Beautiful code should “weigh” just enough to get the job done, and no more. The weight of software should be a function of the business value that it is providing, and there should be a need – and value – derived for each and every task that the software performs. If the code weighs more than the value being derived, it should be scrapped or re-cut. Conversely, some code returns a great deal of value in comparison to its weight (and other code), which translates into higher profit margins or savings in terms operational efficiencies in some way for the owner of the code.

Diamond settings are the platform in which the diamond sits.

The setting is the business context and need that the beautiful code fulfills, and what is beautiful in one setting may not be so beautiful in another. For example, a beautiful client/server, Windows®-based application may be elegant as an in-house, single-customer solution, but it will not shine in a Software-as-a-Service setting intended for a broad customer base.

Code Isn't Beautiful
Beautiful Code
Wikipedia.org: Diamond (gemstone)
The Four C's of diamonds

And many thanks to Bidyut Raj.


Anonymous said...

sqlite. seriously, check it out.

January 17, 2010 at 3:57 PM
Anonymous said...

So far, the number of points and ideas given here are actually what I was looking for from the last few hours, hopefully this would proved to be the best guide, if further information taken out from the same platform to assist in more efficient way. Check http://great-college-paper.com/ for best Papers

January 4, 2015 at 2:54 PM
shabbat candles said...

The specific illustrations you've made, the straightforward blog navigation, the relationships you make it possible to create - it's many excellent, and it's really assisting our son in addition to the family imagine that that subject matter is satisfying, which is extremely important. Thank you for all!

February 14, 2015 at 11:35 AM
Anabel Atkin said...

I've learn some good stuff here. Certainly value bookmarking for revisiting. I surprise how much attempt you put to create this sort of magnificent informative web site. Check business phone calls for best Calls.

February 17, 2015 at 3:06 PM

bettys beauty blog has been selling the best anti aging cream online and Betty has tested all the products on herself. Find out how Bettys has improved her skin and wrinkles on her face!

May 24, 2015 at 7:50 AM
Rai Shanawz said...

Good informative post, thanks for sharing.

October 11, 2015 at 4:01 PM
for IT the said...

Beautiful Java SE & Java EE Code has sparked Java Training Institutes Specialists versus Generalists Java SE & Java EE easily maintained over time J2EE Training in Chennai JavaSE & Java EE Training Courses Provider Java Course in Chennai provide Java career certification courses guidance Java EE Training Specialists are well-versed java j2ee training institutes in chennai Good generalists can perform Java Training Institutes in Chennai diamond metaphor defines beautiful Java SE & Java EE code Java Training in Chennai technical specialties Java Se & Java EE Programming Languages IT Technical Articles proportions, finish, symmetry Java Interview Questions

January 10, 2016 at 6:32 AM

The summary of an academic essay sets the quality for the complete paper and has a strong effect on your rating. This object will give you three tips that will help you write top quality summaries to your college papers.

January 22, 2016 at 3:59 AM

If you really want to improve essay writing for your college paper, you have to read all best essays review; for knowing the basic error and problem to write an essay for your college paper.

April 19, 2016 at 2:51 PM
Ellen R. Smith said...

If you do not write assignment, you must have to say your frient or other do assignment for me. Cause you don't know how to make quality assignment for your classe.

May 30, 2016 at 3:16 AM

This is the best way to have pokemon go cheats online.

August 22, 2016 at 8:35 AM
Deepakala said...

Thanks for all your information.Website is very nice and informative content.

Software Estimation Techniques Training in Chennai

September 23, 2016 at 3:17 AM

This is really great article about the diamond

September 23, 2016 at 8:31 AM

Post a Comment