Tuesday, October 2, 2012

Ruby and the joy of programming

Years ago I used to solve many mathematical problems in Ruby. Looking backwards, I find difficult to explain my decision, because if I remember correctly Ruby was slow compared with C++ or Perl, and since most of the time I ended using a brute force approach to solve what my imagination could not solve efficiently I often ended awaiting longer times before obtaining my answers.

However, I can clearly remember that for the first time in my conscious programming life, I was happy and I was enjoying my time with some programming language. So I didn't worry too much about some additional time awaiting a stupid brute force solution. I was solving mathematical puzzles for fun and with Ruby I could quickly test some crazy ideas, leave the process running and go to do other things. Ruby was powerful, concise, elegant, and more importantly it didn't force over me its formatting policies or push me to do things in some way I didn't like to. I had finally found a language where everything fitted in place and seemed natural. I thought: this language must have been created by someone who really likes having fun while programming.

And indeed it was. Ruby was created by Yukihiro Matsumoto (aka Matz), who is one of my heroes actually. I found an interview he gave about Ruby and there he said something that really touched a fiber inside me, I have always used his words as an inspiration:

Fun to use. Freedom to choose. This man taught me all.


Is it a sin to look for fun in our craft? I'm not going to say that programming is the the hardest work in the world, neither the most complex, I believe it has its fine share of angst and grieving but not too much. What I can say for sure is that sometimes as a programmer you'll find yourself cornered for some nasty bugs or trying desperately to find a way to make something work between layers and layers of abstraction and piles of ugly code behind a deadline. And at those dark times getting a helping hand from the language or framework that you are using is really priceless. It would save your head of some heavy banging against the wall. If we as programmers can not make things easy and fun to use for our fellow peers, who is going to do it? Even if we don't get it right the first time, we must not admit defeat and try to do things better the next time. This is important for every programmer but for language and API creators is crucially important. I call this the rule of the "joy of programming". If it is not easy and fun to use, don't bother.

From these years many things have changed, I no longer use Ruby frequently, I found new languages with different approaches to programming, learned some new things, but the spirit of Ruby is always with me even now, and I think it would follow me forever, in every thing I'll create I'll try to make things the way Matz tried. Nothing less.

So I was remembering that quote, and I recalled that I used it for years as a programming exercise for possible hires. I gave them this "encrypted" text

along with the frequency of characters used by the language of the original message sorted from more to less used:

freqLang = "TEOIARNSHMLYGCPUDWFBVKJXQZ"

and it was their task to find the table of frequency of the "encrypted" message, compare it with the one given and substitute the characters. It was not trivial as FizzBuzz at all but with the steps to follow already mentioned in the problem many candidates found the problem interesting and fun. The secret message of course was the nice part for me. So here is the solution to my question in Killa:

After all I created Killa because I wanted to have more fun programming in Lua.

3 comments:

  1. Hi Laurens. An interesting looking language, though not intutively obvious how it works.

    I answered your challenge in PHP. If I knew Ruby better I would have used that. Not accounting for comment lines, I solved it in just 1 more line than you. PHP is odd. Not particularly elegant, it's 'swiss army knife' is an incredibly flexible array structure. Happy to share my code if you're interested.

    ReplyDelete
    Replies
    1. hi! it would be fun to see the PHP solution

      Delete
  2. minecraft java Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.

    ReplyDelete