Marcel Molina: Beautiful Code
What Makes Code Beautiful
“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.
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.
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.