Follow me on Twitter Twitter_16
Subscribe to my RSS feed Rss_16
Posted over 8 years ago

The value of elegant code

I read a really “interesting blog on Chef vs. Puppet”: today. A friend of mine pointed me to it because he really enjoyed the following quote from the article, “This zealous hunting of unquantifiable elegance feels, to me, to be endemic in the ruby world.”

I will agree, there is some truth in that. I find that ruby developers tend to spend a bit more time trying to perfect their code base. Perhaps they do over-value ‘elegance’ a bit, but perhaps the value of elegance manifests itself on a more long term basis.

I agree with the author that ‘elegance’ isn’t really quantifiable. It’s a ‘feel-goodness’ about the code you write. Their are code complexity analysis tools that I could argue are measures of elegance. I would guess that code bases that developers agree to call elegant would also score well on code complexity analysis reports, but that’s outside the scope of this post.

To me, a code base is elegant when it’s…

  • Simple
  • Intuitive
  • Easily maintained

… and these generally manifest themselves in quantifiable ways:

  • Few lines of code
  • Easily followed by other devs
  • Good OO design: High cohesion, low coupling, etc.

The author jests about the value of having few lines of code:

Inadvertently, however, the sentence before that quote is the big problem with chef: The big advantage Chef has over Puppet is that the codebase is 1/10th the size and it is pure ruby, including the recipe DSL. I am, unfortunately, not measuring the quality of my configuration management system based on how many lines of code it is. Nor am I measuring it’s ‘ruby purity’. These are, however, Chef design goals. This zealous hunting of unquantifiable elegance feels, to me, to be endemic in the ruby world.

However, I would argue that there is value in having fewer lines of code. As a developer, reducing a code base by 90% without loosing functionality and while maintaining readability and good OO design is favor to anyone else that touches that code. As a result, subsequent features will likely be developed more quickly, new developers will be able to get up to speed faster, and bug’s will become easier to locate, and fix.

I’ve found the following to be true. Fewer lines of code means…
I have to spend less time looking through code to find the line I’m interested in.
I have fewer lines to look through when trying to identify dependencies on a particular line/class that I’m modifying.
I have fewer places to refactor and test when doing major changes on the code base.

As an end-user of that product you will see the results of an elegant code base by faster, more stable development on the app/program and fewer bugs.

With all

comments powered by Disqus