The Beauty of Ruby

I’m more of a fan of Ruby than Rails. Sure Rails is good, but Ruby is way better. I’m trying to put some time aside to learn a little bit of Polish. As a result, I was a frequent visitor to www.dict.pl. After a couple of days of using this, I’d had enough. Too slow. Too restrictive. Too crap! Time to turn this around.

I wrote a simple English->Polish translator application in Ruby. It does all the usual stuff such as add new words, search for words in either language, and maintain the words in named bundles. The challenge I set myself as a novice Ruby programmer was to implement the core set of features knowing that the code would be fat and not very pretty. I then aggressively sort to refactor the code to reduce its size, whilst increasing the feature set.

The core translation engine started out as 120 lines of code with just the add new word feature. Since then I’ve learnt a lot about how to structure Ruby programs and the effective use of closures, iterators, containers and yaml. In the process, I’ve added search, display and bi-directional features to the translation engine and reduced the lines of code to 114.

I have a new found respect for Ruby the Language. It is the most expressive language I played within in a long time. Also, contrary to what many non-Ruby programmers tell me, Ruby is readable when written well. Unfortunately, on my travels through the web, I have seen some really awful Ruby code and this stuff is truly poisonous. Bad Ruby is completely unfathomable. A ticking time bomb. However, well-written is Ruby is sublime. I truly believe that there are no shades of grey here :-)

Leave a Reply