The 4 C's of Elegance

After my last blog post a couple of friends and I were discussing the "best" solution to the FizzBuzz problem.  My solution is the one I consider to be the most elegant, because it satisfies the 4 C's of elegance.

The first 3 C's are obviousA solution should solve the problem (be correct) with as little effort as possible (be concise) while being as easy as possible to understand (be comprehensible). The last, not so obvious C is compromise: in almost all cases an elegant solution will have to break a 'best practice' rule.

In FizzBuzz there are compromises made to balance conciseness and comprehension. For example, not using {} to enclose the "if" statements. That is a superficial, stylistic choice. But the use of a temporary string, and the use of the += operator on it, both have the potential to impact performance. The more technically correct method, in Java and C# at least, would be to use the StringBuilder class, or to not use a temporary string at all. Both of those options make the code ugly to read and in most real-world situations the performance degradation would be imperceptible.

The 4 C's hold up well when applied more broadly. To bring elegance to my career path I needed to change organisations. Where I was, the ability to achieve my goals at all (correctness) was questionable, and it was certainly not going to be easy or easily understood. So I went looking for, and found a job that satisfies the first 3 C's nicely. The compromise component was difficult: I had to reduce the amount of time I spend with my family as well as move from a into the private sector.

But already we have a noticeably better, more elegant life. I don't worry about work when I'm home, so I'm more present when I am with the boys. I've started cycling to work which frees up the time I used to spend at the gym. There's bonus elegance points here, with my exercise providing both fitness and transportation. So far it looks like those compromises were the right ones to make.

Too often I've seen people (myself included) let dogma about the detail stop them from reaching the broader goal. An organisation doesn't (or shouldn't) want a good CMMI score, it wants to make great software. My goal isn't to spend lots of time with the boys, it's to be the best dad that I can.

The 4 C's are a valuable tool for ensuring decisions, about coding or otherwise, are focused on producing an elegant outcome.

comments powered by Disqus