Should I Learn Python or Ruby next?

Gregory Ewing greg.ewing at canterbury.ac.nz
Tue Jun 22 20:56:41 EDT 2010


Thomas Jollans wrote:

> "Everything is an object" in both languages, or so they say.

That's really a meaningless statement, because it depends on
what you count as a "thing". But there is at least one thing
that is an object in Python but not in Ruby. There are no
stand-alone functions in Ruby, or callable objects in general.
The only way to invoke code is to call a method of some
object.

This can be confusing to someone coming from Python, because
you can write what *look* deceptively like top-level function
definitions. But they actually become methods of class Object,
which is inherited by everything, and thus become implicitly
available in any other method.

You can ignore the difference until you start trying to
use modules. Ruby has something it calls a "module", but it's
really more like a mixin class. If you try to think of it and
use it like a Python module, you'll get very confused and
frustrated and pull out large chunks of hair. At least I
did until I figured out what was really going on behind the
scenes.

Having used both, I find the way that Python handles namespaces
to be greatly preferable. This may be partly because I'm more
familiar with it, but I think there are ways in which it's
objectively simpler and more useful for organising code.

-- 
Greg



More information about the Python-list mailing list