Friday, November 2, 2007

RubyConf 2007: What Makes Code Beautiful?

Marcel Molina began his talk waxing philosophic on the topic of beauty.

Why is your wife's face beautiful? It's an ephemeral quality. There is a deeper meaning. "You're not saying, her jawline is the golden ratio."

As the talk proceeds, he goes from abstract to concrete. From classic literary thinking on the subject, to agreeing on a definition, and finally application to ruby code.

For the sake of discussion, he uses Thomas Acquinas' definition of beauty:
  • proportion (ratio of parts and economy of size)
  • integrity (glass hammer analogy)
  • clarity
"Each of these are necessary, but none are sufficient."

For example, the following ruby code, borrowed from Ruby Quiz, is missing clarity:

H,B=%w'HomePage w7.cgi?n=%s';c=CGI.new'html4';n,d=c['n']!=''?c['n']:H,c['d'];t=`
cat #{n}`
;d!=''&&`echo #{t=CGI.escapeHTML(d)} >#{n}`;c.instance_eval{out{h1{n}+
a(B%H){H}+pre{t.gsub(/([A-Z]\w+){2}/){a(B%$&){$&}}}+form("get"){textarea('d'){t
}+hidden('n',n)+submit}}}

Code can and should be beautiful.

1 comment:

sbeckeriv said...

http://rubyhoedown2007.confreaks.com/session09.html

same talk from the hoedown? confreaks seem cool