When i was first learning Ruby i, like most people, picked up two books. The first was the wonderful pickaxe book; the second, the no-less-wonderful Poignant Guide to Ruby by everyone’s favorite mad scientist – Why the lucky stiff.
When virtually flipping through why’s lovely creation one of the things that caught my eye was a a statement early on in which he simply asked us readers to “read the following aloud to yourself” and followed it with a small block of ruby code:
5.times { print "Odelay!" } |
I, being in the comfort of my own home late at night, obeyed and read “five times print odelay!”. I chuckled and moved on. But he persisted asking that i then read another block of code:
exit unless "restaurant".include? "aura" |
And once more i obeyed chuckling even more at the concept of a restaurant aura. I’ve often used this as one of the reasons why i love Ruby. When written right it just sort of makes sense. You can read it and understand it more-often-than-not. It’s not the insane business speak like COBOL or the drawn-out run-on sentences of Java, but just simple little statements that do their best to not confuse the reader.

Why is all this interesting? Well i was wandering about the bundles menu in TextMate today and stumbled across the ability to Speak Selection. I hastily highlighted a line of the Javascript library i was working on and hit Speak Selection. What i got was something between a three-year-old telling you about their day and a speech synthesizer being circuit bent. I copied in Why’s first example and did the same and was rewarded with “five dot times print Odelay!”. Not exactly how i had read it but still mostly understandable.
So this begs the question: could ‘speakability’ be a viable way to determine if code is understandable? If you can actually read your code aloud – and have it explain in more-or-less english what it is attempting to do – it would seem that there is a much greater chance that the next person to look at your code will be able to interpret it as well.
