< lxml 0.9.1 released!
the Infrae OAI-PMH components >

[Comments] (33) Ruby misconceptions about Python:

I just ran into a rather misleading article claiming to compare Ruby and Python. Let's please be done with some of these misconceptions:

So, Ruby advocates, please consider stopping to spread the following misconceptions about Python:

If you want to advocate Ruby over Python, advocate things like support for anonymous blocks. That's something neat that Python actually doesn't have.


Comments:

Posted by amk at Wed Apr 12 2006 20:29

Small correction: new-style classes were added in Python 2.2, not 2.0. 2.2 was first released in December 2001. The cyclic GC changes were in 2.0, which was released in October 2000.

Posted by Seo Sanghyeon at Wed Apr 12 2006 20:39

Nitpick: new-style classes were introduced in Python 2.2, not 2.0. Cyclic GC was introduced in Python 2.0 though.

Python 2.0 was released 2000-10-16.
Python 2.2 was released 2001-12-21.

Posted by boa13 at Wed Apr 12 2006 20:58

As far as we know, the article you're debunking was written by a single, misled person. I think your rant on Ruby advocates is unwarranted in this context, since the article does not have the support of a significant or meaningful portion of the Ruby community. Otherwise, good points.

Posted by infidel at Wed Apr 12 2006 21:02

I think this may be the only time I've ever seen anyone insinuate that Python is a B&D language. The author is clearly a raving lunatic.

Posted by jsh at Wed Apr 12 2006 21:02

There's a world of difference between easy and possible.

Posted by Jonathan Ellis at Wed Apr 12 2006 21:10

"I think your rant on Ruby advocates is unwarranted in this context, since the article does not have the support of a significant or meaningful portion of the Ruby community."

I've seen the same FUD about GC and (particularly) OO from many other ruby-ists.

Posted by anders pearson at Wed Apr 12 2006 21:16

the wayback machine has this article from october of 2003, so it's at least that old: http://web.archive.org/web/*/http://www.rexx.com/~oinkoink/Ruby_v_Python.html

Posted by Marc at Wed Apr 12 2006 23:16

First off, I haven't used either Python or Ruby extensively. I have no particular loyalty to either one, but they both look like fine languages.

My guess is that the "Python OO bolt-on" idea originates from http://www.python.org/doc/faq/general/#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list and from http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls (which in my opinion makes a good argument for qualifying instance variables, but a poor argument for why "self" has to be in the parameter list).

Whether you like Python or not, it seems pretty clear that Ruby was designed with objects in mind (as a result of being influenced by Smalltalk). Python gives the impression that it did or does put less emphasis on objects. That said, it seems to have done a nice job of evolving to support OO in a pretty nice way. And of course there are lots of applications where OO isn't even necessary and people may like that it's not forced on them.

It's interesting to me to note how much Ruby vs. Python bashing is going on (originating from both sides). Kind of a shame really.

Posted by Martijn Faassen at Wed Apr 12 2006 23:18

Sorry for getting my python versions mixed up, thanks for the correction. And thanks anders for finding out that this article is quite old. It was brought to my attention today as it was a popular delicious link, so I still hope my feedback is useful.

And indeed, like Jonathan, I've seen FUD like this before
from other ruby-ists. I'm sure there are many who know better
and this message isn't for them.

Posted by Myrddin at Thu Apr 13 2006 00:00

Comments on the various qualities of languages often is misleading... it is really a complaint between the quality of the predominant EXAMPLE CODE for that language.

Right now the most visible example code for Ruby (Rails) is heavily OO, makes strong use of reflection and dynamic function binding, heavy use of closure and lambdas, and is a very complex project with a LOT of documented, easy to read code.

This makes the features of Ruby very evident... most people who pick up Ruby are gonna be at least looking at Rails. The transparancy of Rails means that you can see where all the cool features of Ruby are being used, right up front and in your face. It shows you good practices for using them yourself.

I have no Python experience. But perhaps the most visible pieces of Python code are NOT heavily OO. Perhaps they do not use method rebinding, and perhaps many of the features Python offers are not being taken advantage of. If that is the case, then it's not difficult to see why programmers who look at both languages come across with the impression that Ruby has more features to offer.

For a new user, a language is only as good as the best example code they see... if the code they find while learning how to program in that language does not take advantage of the language features, then they will not learn about those features. They won't see them in use, won't see how to put them to use, won't see their utility. Features described in a manual don't mean squat until you've seen them put into practice.

Posted by Amir Salihefendic at Thu Apr 13 2006 00:39

Great points!

In the end of the article the author writes:
"Ruby is capable of Perl-like one-liners that can be used on the command line for system administration. Python is unsuitable for this."

This is BS... Python is a super language to write shell scripts in! They are probably 3 lines longer, but hey, in the future you can actually read them!

An example: Imagine that one wants to grep in a directory after some specific text (that isn't in a .svn directory). Here is a little Python script that does that:
import os, sys
findcmd = 'grep -R "text to search" .'
print "Searching...:"
for f in os.popen(findcmd).readlines():
if str(f[:-1]).find(".svn") == -1:
print str(f[:-1])

Of course, one could also do...:
grep -r "text to search" * grep -v ".svn"

Anyway, my point is: It's super easy to use python as a scripting language - and it is used by a lot of big companies this way (like Google ^^). So stating that Python isn't suitable for system administration is complete bullshit.

I mostly like Python because of its kick ass syntax and slick standard library.

Posted by Tomas at Thu Apr 13 2006 01:35

I'm no Python historian, so I couldn't say if OO in Python is actually "bolted on" or not. But, I was at least *hoping* it was, because why else does it *feel* like it? Because of poor design?

Posted by Jacius at Thu Apr 13 2006 03:15

"I wonder how Ruby deals with the interaction between its garbage collection and C libraries that use malloc? I can imagine this might sometimes make things a bit more difficult."

I am not a ruby god nor a C wizard, but I have some experience writing C extensions (libraries) for Ruby, so perhaps I can share some knowledge.

Basically, when you create an object in C that the ruby garbage collector will watch, you can specify two C functions: one to be called when the object is marked by the GC, and one when the object is swept by the GC. So, it's not too bad; I don't know much about C libraries for python, so I won't make any judgement calls on its relative merits.

On some level, it's useless to argue about which language is better overall, because of the Blub phenomenon (as described by Paul Graham). At risk of angering Python users, I'll note that if Paul Graham's hypothesis is correct, it would indicate that Ruby is more powerful (if only slightly), because while Ruby users tend to consider Python as missing some important features, I think that Python users just think Ruby is weird and different with a bunch of extra features you wouldn't really use (I know that's what I first thought of Ruby when I was switching from Python).

I'll also point out that even if "Python can do Ruby feature X too!", that doesn't mean that it is as *easy* to do it in Python as Ruby. (You can break concrete with a sledgehammer, but that doesn't make it as powerful as a jackhammer, does it?)

Now to placate Python users, I'll add this: Python definitely has a wider selection of extra libraries, though... at present. ;)

Posted by TomP at Thu Apr 13 2006 04:49

Amir,

The assertion was "Ruby is capable of Perl-like one-liners... Python is unsuitable for this." You're response does not address one-liners. In fact, the original statement was quite correct. The (ridiculous) indentation rules Python imposes make it impossible to convert most scripts into one-liners.

TomP

Posted by Joe at Thu Apr 13 2006 05:01

Paul Graham's Blub story was made up to advocate a language: Lisp. His assertion that some languages are more powerful than others is indisputably true but his implication that merely adding features to a language makes it more powerful is not.

Adding more features will eventually get you Visual Basic.

In fact, he doesn't even really say that what make Lisp more powerful features. He cites macros, the lack of syntax and interchangability of Lisp code and data.

He's not talking about features, he's talking about elegance. It's entirely different.

Posted by Doug at Thu Apr 13 2006 06:02

Joe,

When Jacius is referring to the blub paradox, I believe he commenting on Paul Grahams idea that you are limited in perspective by the most powerful language you use. I've heard *many* Python programmers slam Ruby when they haven't really used it. I personally have used Python for many years now, and Ruby for going on two years now, and imo, Ruby is more powerful. It's not like the difference in expressiveness between say Java and Python, but Ruby has a pretty definite lead.

The problem with Python's OO really stems from a couple of things as far as I'm concerned.

1- The lack of private variables, and the use of conventions like underscore and double underscore to indicate private. This is a pretty unsightly convention, and it's pretty jarring to OO purists. One of the presumptions of OO is the ability to protect your private member variables.

2- The use of explicit self in all functions within a class. I understand there are some times where it could be possibly ambiguous, but personally I've never encountered those cases in almost 5 years of using Python every day at work.

I really, really think those two issue listed above are what makes people think Python has poor OO support. I would bet money that just dealing with those two issues in a more elegant fashion would eliminate 90% of the OO complaints.

That being said, anyone who puts Python's OO support on a par with Ruby's either doesn't understand OO, or hasn't seriously used Ruby. Ruby has one of the best designed OO systems I've ever seen (never have used smalltalk), and when you use Ruby it's very apparent how well it is designed.

The vast majority of the people I've read writing comparisons between Ruby and Python have primarily used one, and only marginally used the other. Most of the comparisons are also highly polemic in nature (admission: even one I wrote), it's unfortunately all too easy to do.

What people need to understand is that Ruby and Python are two of the best languages out there. They are both really great languages, and I use both of them on a daily basis. They both do things well, and both of them have some blemishes and ugly parts in places. A huge portion of your preference boils down to a simple matter of taste. Get over it and go write some code.

Posted by norm at Thu Apr 13 2006 07:20

1- The lack of private variables, and the use of conventions like underscore and double underscore to indicate private. This is a pretty unsightly convention, and it's pretty jarring to OO purists. One of the presumptions of OO is the ability to protect your private member variables.

2- The use of explicit self in all functions within a class. I understand there are some times where it could be possibly ambiguous, but personally I've never encountered those cases in almost 5 years of using Python every day at work.

I find these arguments insane (like the indentation one). They don't describe any missing functionality or anything at all other than syntax. There's nothing more you can do if your language has implicit self and/or enforced private varibles. In fact there is less you can do.

I just don't get these arguments at all...

Posted by Amir Salihefendic at Thu Apr 13 2006 10:30

TomP:
He thinks that writing "system administration" scripts implies one liners, and that is BS. My point: You don't have to create one-liners, using Python you can write 3 liners that are readable...

Posted by Martijn Faassen at Thu Apr 13 2006 10:56

Doug: can you give examples of Ruby's OO support having features that Python's doesn't? Or is this more a feeling
of elegance than a feeling of features?

The 'self' one doesn't cut it for me; I was one of those people adding prefixes to my member variables in my C++ code to identify them within methods, so that seems like a great idea to me. Private variable privacy is a stronger point, though not one that bothers me (Python has a different perspective which allows properties). If these *aren't* the reasons, you have just made a statement without backing it up ("Ruby has stronger OO support than Python").

Note for all that I'm not in fact comparing Python with Ruby in this article - I'm commenting on a flawed comparison. Ruby is a fine language that I might be advocating it myself if I didn't already use Python. Ruby and Python both have strengths that the other language doesn't have. Multiple implementations of the language, unicode support, continuation support, anonymous blocks, things like that. There are real differences in the OO support as well.

Show me the differences that matter to you in practical programming, don't just make claims about superiority or inferiority. If you want to compare the languages, please discuss real differences, and do not perpetuate FUD ("Python's OO is bolted-on"). Ruby is a fine language and can clearly stand next to Python without having to make sweeping inaccurate statements.

Posted by Douglas Livingstone at Thu Apr 13 2006 15:04

> They don't describe any missing functionality or anything at all other than syntax.

Syntax is important, and if one syntax readily exposes more features than another, that's great.

Doug's two points represent "feeling of elegance" rather than "feeling of features". There's a pragmatic point in there though: more elegant features will be used more than inelegant ones.

This even affects the design of the built-in language functions:

"In fact, implementing len(), max(), min() as a built-in function is actually less code than implementing them as methods for each type."

In Ruby max() and min() are part of the Enumerable mixin. You don't have to break out of OO to implement things in less code. Is being able to write less code to do the same thing something which would lead to a "feeling of features"?

The Enumerable mixin is possible because of Ruby's OO implementation: being able to run code in the scope of the class. It means that there is one obvious and simple way to do metaprogramming with objects. In Python, it's a bit of a mess really: http://blog.ianbicking.org/more-on-python-metaprogramming.html

You might say "it's only syntax", but when people are doing "deep tricks, including putting the interpreter temporarily into trace mode and changing metaclasses around" to get closer to that syntax, you've got to admit it is worth a closer look.

Douglas

Posted by Amir Salihefendic at Thu Apr 13 2006 15:11

My post on Ruby vs. Python and what I think is the main difference:

http://amix.dk/index.py/permanentLink?id=112

Posted by Martijn Faassen at Thu Apr 13 2006 15:29

Douglas, you are pointing out a possible real advantage of Ruby's OO implementation. Metaprogramming is possibly more elegant in Ruby. I can't really judge it myself, but I heard a Python programmer once say that Ruby allows more
easy implementation of domain specific languages in Ruby, so I'll buy it.

That's fine. That still doesn't lead to statements like "Python's OO is bolted on", but it does say that "Ruby has remarkably elegant facilities for OO and metaprogramming". Good for Ruby; I should check it out. "Python has elegant facilities for OO" is true too, however. Metaprogramming is likely harder in Python than in Ruby - it's a language philosophy decision that has pros and cons, which by the way also doesn't lead to statements like "Python is a bondage and discipline language". :)

By the way, note that Python allows classes to implement __len__ (and other sequence related methods), and you could of course put an implementation into a mixin. It's just the calling pattern where you need to use len(). I personally do not quite understand why len() can be expressed more succinctly as a function than as a method anyway.

Posted by Alec Munro at Thu Apr 13 2006 17:15

As a Python programmer who's dipped his toes into Ruby a time or two, and build some fairly complex OO systems in Python, I feel very confident saying that Python's OO has never inhibited what I could accomplish.

Regarding explicit self, I'm a big fan of cleaning out redundant references, and this annoyed me at first. But what I've found through use is that I very rarely end up with dozens of 'self.' references in a method call, and when I do, it's usually a sign there's a cleaner way to write the method.

Furthermore, I find explicit self a great help in understanding the differences between functions and methods. I believe it encourages the use of OO by making it less magical. Since most programmers come at it understanding standard function calls, it's a trivial step to understand that someObject.someMethod() is equivalent to someMethod(someObject).

Python works for me because of the lack of magic. I very rarely have to guess what will happen when I run something in Python, which is something that I have not experienced with any other language. It comes down to allowing me to spend my time thinking about the logic of a program, rather than the programming language.

To be clear, I will probably continue to use Ruby, and there are features in it that I think are really neat. If I get the opportunity to work on big Ruby projects, I will jump right in.

Posted by anonymous@192.85.47.2 at Thu Apr 13 2006 18:03

Martin,

"Python's OO looks bolted-on" may be infuriating, but it isn't repeated in malice. Let's take another look at those two issues.

Why do people think a "true" OO language needs private attributes? Because the heavy weights Java and C# have them, and every beginner's book explains at length why public attributes are evil and how you should only access attributes via accessors.

And the self reference looks not only superfluous but also eerily familiar to those of us who used to add a pointer to our structs to bolt OO on to C back in the '90s.

Is this an unfair evaluation? Yes, it is, but I don't see it changing any time soon.

And if you think you have it bad, remember those JavaScript programmers. "No classes? Sheesh."

Posted by Ian Bicking at Thu Apr 13 2006 18:42

I think reports of Ruby's DSL-accessibility are somewhat overreported. We do many of the same things in Python, we just don't call them DSLs.

Posted by Matt at Fri Apr 14 2006 05:44

While it might be unfair to call Python's OO support 'bolted on', I still feel that Ruby's OO is a lot purer and more elegant. Python's OO is very powerful, but in more of a hacky sort of a way - Ruby, being a close descendant of Smalltalk, tends to get things right in this department right from the ground up.

In particular the distinction between 'old-style' and 'new-style' classes in Python I always found to be a major wart.

Posted by Matt at Fri Apr 14 2006 05:49

It's not so much that Ruby has OO features which Python lacks, it's that Ruby's OO is cleaner, tidier, more elegant, and has stayed more consistent as the language has grown.

Posted by Martijn Faassen at Fri Apr 14 2006 18:33

I will accept the argument that Ruby's OO is more pure than Python's - Ruby does indeed have a strong smalltalk heritage. and benits from that. old-style and new-style classes in Python being different in Python isn't pretty, and it's historical baggage that Ruby doesn't have. Elegance is clearly difficult to convince anyone of.

I've since found some *good* discussions comparing Ruby with Python, and while I agree with all of the arguments it's certainly an interesting perspective:

http://opal.cabochon.com/~stevey/blog-rants/anti-anti-hype.html

http://opal.cabochon.com/~stevey/blog-rants/bambi-meets-godzilla.html

even though I still appreciate a reasoned discussion above an emotional one on this (also because clearly with all the Ruby hype recently I've lose the emotional argument :).

Posted by Martijn Faassen at Fri Apr 14 2006 18:34

In my previous comment, I mean of course "while *don't* agree with all of the arguments." and "I *would* lose the emotional argument". Typos, typos.

Posted by Ian Bicking at Fri Apr 14 2006 23:49

It's unfair to criticize Python for its strong commitment to backward compatibility, that causes the occassional wart to persist even after it has been fixed. We don't go harping about $_ in Ruby.

Posted by Oinkoink at Sat Apr 15 2006 21:13

I confess to having written this article back in the Pleistocene. I've since changed my mind on much of it, and I removed the link on my home page ages ago. I was not aware that it was even visible to anyone.

Indeed at the time I wrote this, I'd only had experience with Python up to version 1.5.2, though I'd heard about newer developments and proposals.

I've learned a lot since, and though I still prefer Ruby to Python, I do so for better reasons, and I'm sure I'd write a quite different article today.

Regards, Bret

Posted by Martijn Faassen at Tue Apr 18 2006 11:05

Oinkoink: wow, feedback from the original author, I didn't expect that. What was happening is that this was a popular delicious link (for at least the categories python and ruby), so people were being exposed to it, including myself. I had no clue as to how old it was, and the age context explains some of it. My apologies if I overreacted - I just didn't want these memes to go out amongst a possibly less informed set of people.

It's of course fine to prefer Ruby - it's a fine language that has advantages above Python (and vice versa, of course). Perhaps we will see an article with an improved comparison in the future.

Posted by Oinkoink at Thu Apr 20 2006 06:29

I'll have to learn more about Python's current capabilities first, but I hope to get around to updating this article.
Especially since it turns out that someone has actually read it! Beyond the language issues per se, I would like first to learn more about the available libraries in Python. I suspect both Ruby and Python are missing nifty library support available in the other language.

Regards, Bret


[Main]

Unless otherwise noted, all content licensed by Martijn Faassen
under a Creative Commons License.