RubyConf 07: Marcel Molina: What Makes Code Beautiful?

by javery on November 2, 2007

So I got to Charlotte last night and checked in, it was getting late so I didn’t join the crowd hanging out in the hotel lobby and just turned in. This morning the day started with some hotel breakfast and then on to the first talk.

Rconf

The talk focused on what is beauty and how we can apply that definition to code. Marcel Molina walked through classic definitions of beauty and focused on three main properties: Proportion, Integrity, and Clarity. He then pulled up a code example which was written to basically parse XML values into their native ruby types. It was a great tactic because you could tell just about everyone in the room looked at the code and could hardly figure out what the hell it was doing. Molina then tried applying the three properties of beauty to this code.

Proportion. How much code is used to accomplish the goal? In this case it was a full slide of code to accomplish what was later refactored to be a simple case statement. The code you write should be proportional to the problem you are solving. For me when I start writing code I usually catch myself and think "There has to be a better way" and there usually is.

Integrity. How well does it do it’s job? The first example of code didn’t work very well. It was slow and even had some memory leaks.

Clarity. How long does it take you to explain the code to someone else. In the first example Molina spent a good 5 minutes explaining to the crows how the code worked. We all understood the second example right away.

Molina also covered perhaps one of the most important parts, the balance of these three properties. You can have a very concise piece of code that isn’t very clear (think everything on one line). You can have very clear code that doesn’t work, etc.

Overall it was a great talk and a great way to start the day and the conference.

-James

{ 1 comment }

onSlaught November 2, 2007 at 8:18 pm

Proportion is what usually gets me. Sometimes it a couple a days later when I realize there was a better way.

Comments on this entry are closed.

Previous post: Getting ready to head to RubyConf

Next post: RubyConf 07: Jim Weirich: Advanced Ruby Class Design