November 02, 2007

Posted by John

Tagged presentation and rubyconf

Older: KYTCR Part 1: Backups

Newer: Jim Weirich: Advanced Ruby Class Design

Marcel Molina: Beautiful Code

What Makes Code Beautiful

IMG_1139.JPG

“at the risk of sounding emo” – during his explanation of why he wanted to determine what beautiful code is

“her jawline is the golden ratio” – how do you explain the fact that you think your wife is beautiful

“i realize the fact that some people are going to think i’m totally wrong, but that’s not important” – this is not deep and rigorous, it’s only what is needed to apply it to the current (software development)

Thomas Aquinas definition of beauty

  • proportion – economy of size (smallest size needed to do the job) and ratio of pars
  • integrity – thing being well suited for it’s purpose
  • clarity – simple and clear (there is a difference between sophistication and complication)

Showed an example of a CoercibleString which allows a string being automatically converted to string, boolean, integer, or datetime. Very cool idea. He created it for web services project. Really sweet idea. I’ve parsed a lot of XML from web services and that is always annoying. Refactored it to String.coerce which is about 6 lines instead of 20.

IMG_1138.JPG

The first version felt cool and interesting but it turned out to be terrible.

Proportion/Integrity/Clarity – Each are necessary. None are sufficient.

Does code quality relate to beauty?

Kent Beck: Smalltalk Best Practice Patters – Recommended reading.

Beauty is a moving target. Ruby in 20 years could be like assembler now a days.

Can you imagine programming without if? If might have been beautiful when it came out.

“An expert is a person who has made al the mistakes that can be made in a very narrow field.”

Ruby is optimized for beauty. Try to imagine better modes of expression. Violations of beauty rules (proportion, integrity, clarity) reveal mistakes. Do that enough and you will innovate.

Conclusion

Very interesting. I thought the first example seemed beautiful but I was just looking at aesthetics (tabs, lining up, etc.). Simple, practical ways to analyze code beauty.

1 Comment

  1. anonymouse anonymouse

    Nov 02, 2007

    ironically, it was the naming “CoercibleString” that “smelled”, because it precluded (in at least 2 iterations of his work and one of yours) the obviousness of just placing the static method on the String class.

Sorry, comments are closed for this article to ease the burden of pruning spam.

About

Authored by John Nunemaker (Noo-neh-maker), a web developer and programmer who has fallen deeply in love with Ruby. More about John.

Syndication

Feed IconRailsTips Articles - An assortment of howto's and thoughts on Ruby and Rails.

Feed IconRails Quick Tips - Ruby and Rails related links.