From: Frank Mitchell Date: 2001-10-26T14:51:10+09:00 Subject: [ruby-talk:23400] Re: Ruby and Python: a fuzzy question Dave Thomas wrote: > So, here's my question. As Paul Prescod has said, Ruby and Python are > fairly similar in many significant ways. Despite this, I personally > have never managed to get excited about Python, but liked Ruby so much > I wrote a book about it. Other folks have the opposite experience, > loving Python and not finding much to thrill them about Ruby. Why is > that? Is it some kind of personality clash between the language and > the programmer? Is it liking what you're used to? Is it liking or > disliking the philosophies of the languages' designers? Or is it > something else? As someone who's written a fair bit of Python in the not too distant past, who's written a only little Ruby, and who currently likes Ruby over Python, I'll take a stab at why I like what I like about each: 1. Python's whitespace reminds me of the pseudocode in Programming 101 texts (using Pascal, ugh). It's also a really clever solution, and algorithm, and I like being able to see block structure simply from the layout of code. My only problem with it is in practice: deeply nested conditionals and loops get confusing because there's no explicit "end", and so you have to mentally line up the code. (Why do I have deeply nested control flow? you may well ask, and I can only mumble something about not having enough time to do it right ...) 2. Ruby has a simple unifying concept: everything's an object. Python's is a little more ad hoc: functions vs. types vs. classes vs. modules ..... (Yes, Python 2.2 will begin doing away with the type/class distinction, but I cut my teeth on 1.4, and did most of my work in 1.6 or 2.0.) Similarly, Python has "magic methods" like '__add__' and '__radd__', while Ruby has the method '+', which you can (re)define on any class to take care of the '__radd__' case. I've always liked simple unifying principles, and can put up with the Perlisms in Ruby simply because they're syntactic sugar. 3. Yes, "syntactic sugar". I always tend to be aware of what's going on "under the hood" of any language I work in. Python almost forces you to know what's going on: 'self' is an explicit argument, scopes were (until recently) limited to an easily implementable set, and accessing any feature on an object or module feels like just a hashtable lookup (cascading up to one or more Classes). Ruby has more hidden arguments and defaults; the ubiquitous "self" I don't mind, but I generally shy away from Perlish stuff like: while gets print if /Ruby/ end If I had to sum up, Python feels like what you'd give non-programmers or scripting newbies to do useful programming; Ruby feels like what you'd give old Perl hands to help them write easily maintainable code, and programmers who grok OOP to enhance their productivity. (Check back in a while though, when I try to write a complex system in Ruby and can therefore rant against it at length.) -- Frank Mitchell (frankm@bayarea.net) "What is luck? Luck is probability taken personally. Luck is the excitement of bad math." -- Penn Jillette