The Journey from Python to Ruby Pt. 1

April 6, 2006 by Doug Leave a reply »

I originally started out using Python almost 12 months ago just before the summer of 2005. It was an incredible breath of fresh air, allowing a greater level of freedom than statically typed languages such as Java and a cleaner syntax than PHP and yet still remaining incredibly easy to learn and use.I practiced on everything. Playing around with the libraries and completing challenges. Writing automation scripts for my work and home environment – as advised in the Pragmatic Programming book.

Rails logoThen I came across Rails about 5 months ago. I had no experience with Ruby except the odd article and skimming the odd blog looking on it as something quite alien. Its blocks, verbose camel-case names and slack syntax turned me off from the start. It was the total antithesis to Python. However, Rails certainly began to shift me round as I found it a joy to use and it was quickly replacing my other methods for web app development. I was managing it by learning only the little Ruby I needed – rarely trying to understand it and often simply copying snippets and making them work – I was truly that frightened I’d soil my Python knowledge with a strange arcane formula that seemed totally at odds with Python’s cleanliness and ease of use. How silly of me…

However, I always like to challenge my beliefs at regular intervals so as to ensure I’m not blindly following through faith or ignorance. I furiously trawled through blog after blog. Articles, reviews, comparisons all on the Ruby vs. Python debate – anything I could get my hands on that would reinforce or tear down my own ideas.

I’d fallen into the silly trap of trying to find an answer in the teachings of others rather than finding it through my own experience!

So I committed to learning a little Ruby and I began that journey looking at the odd page of the 1st edition of the ‘Pickaxe’[1] book. It was a little dry at first with some basic concepts and nothing particularly screaming out the: ‘Ruby way’. Looking through Why’s Guide did nothing other than make me think I was dealing with a toy language scoffing at it all the way through and not trying any of the examples…however it planted a seed that was to grow into a tree that couldn’t be ignored. It was then I stumbled across the Try Ruby page with an online interactive prompt and I went through some of the lessons.

Things started to change and it was really quite a powerful shift in view.

All of the snippets I’d grabbed from each of these sources began to fall into place little by little.

Everything is an Object
When I was using the “Try Ruby” page there was a part in the lessons in which I could type:

  1. “Hello Doug”.length

How wonderfully sensible and intuitive, yet…why doesn’t Python do that?

in Python you’d need to type:

  1. len(“Hello Doug”)

Now this is where the experience of doing far outweighed any of the articles or comparisons I’d read on the power, speed, reliability and features of either language. Here I was typing and for the first time I began to feel the beauty in Ruby. The idea that “Ruby is more object orientated than Python” is perhaps misguided and unfair, however, this simple demonstration did show me that Ruby had a consistency in its OO that surpassed Python. That consistency made for a more comfortable fit – for me at least.

Python is a Programming Language
Both Python and Ruby are high level dynamic languages and Python especially does have a nice clean syntax. However, in my experiences using them they began to diverge and I realised over some weeks that Ruby isn’t a programming language in the strictest sense. Ruby is closer to a Human Language and its then that I noticed I was now looking at Python in much the same way I looked at Java after I started using Python. At the time Java began to look uncomfortable, mechanistic, cumbersome, system orientated and far removed from the outside world. There was a large gulf between human and machine. This gulf closed with Python and with Ruby it closed further.

All of those idiosyncrasies in Ruby that I didn’t previously like; The verbose names, blocks, loose syntax, etc. suddenly fell into place. I was dismissing Ruby as if it was a silly machine language I had to understand – rather than a more natural and slightly different human language with an immense power that I could use to express myself.

This could most easily be shown in this excerpt from Why’s Guide.

  1. exit unless “restaurant”.include? “aura”

How much closer could you get to human language? It even uses “?” marks!

Expressive, poetic, artistic are all words I’ve heard given to Ruby and now it was beginning to fall into place. I posted a while back about the differences in the new Ruby site (still to be confirmed) and the new Python site. My comments in those posts now seem eerily fitting for the languages themselves.

George Orwell’s Python
One thing I liked about Python was the idea that there’s only one way to do things. Ruby was completely the opposite and seemed proud to be a language that had more than one way to do things!
I initially agreed with the usual arguments against this Perl-ish approach: Code is less readable, maintainable, etc.
However, as I was using Ruby and reigniting a creativity I didn’t realise I’d lost I began to realise that this ‘one way to do something’ was nothing more than a ploy! A sick charade to make us all into grey, dumb machines of the party! Well not quite – but if there is only one way to do something then the programmer is limited in their creativity. Limiting creativity can only be a bad thing and it may well result in cleaner more consistent code but it also leaves a dullness and lack of life. Although not something I’d missed or even noticed before until I started using Ruby it was an incredibly refreshing experience.

Conclusion
I’ve been happily using Ruby now for the past few months and intend on using it for many more years. I doubt I’ll leave Python behind and I still have scripts scattered across my home and work PC’s with a number of my online projects still using Python they’ll need to be maintained. I still dive into it every now and then but my path seems to be getting significantly red these days and I can see it being taken over completely in the distant future. This blog started off as a Python blog and it seems it may end differently.

If I say one last thing its: Use Ruby – Don’t read about it.

In the next part I’ll post about some of the more specific features of the languages and travel further in depth.

[1] ‘Pickaxe’ is the nickname given to Programming Ruby by the Pragmatic Programmers.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Google Bookmarks
  • BlinkList
  • DZone
  • Live
  • Ma.gnolia
  • Reddit
  • Slashdot
  • SphereIt
  • StumbleUpon

Related

Advertisement

Leave a Reply