Should I Learn Python or Ruby next?

rantingrick rantingrick at gmail.com
Tue Jun 22 21:54:50 EDT 2010


On Jun 22, 7:56 pm, Gregory Ewing <greg.ew... at canterbury.ac.nz> wrote:
> 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.

Although i will admit the chaining of methods compared to the nesting
of built in functions seems more linear-ly natural as in this case...

RUBY:
['one', 'two', 'three'].map{|x| x.capitalize}.join(',')

PYTHON
','.join(map(string.capitalize, ['one','two', 'three']))
','.join(map(lambda x:x.title(), ['one','two', 'three']))

...but i digress

> 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.

Yes i call that "Ruby's Global Nightmare" and the folks over at
SketchUp are learning day by day how this nightmare is going to
undermine the Ruby API. Not only that, but since the API is for
scripting it seems more natural to use Pythonic namespaces so you can
write simple scripts very easily with one or two functions or complete
packages spanning multiple modules without fear of name clashes (ever
tried debugging that! 8^O). Of course you can create a module with
Ruby (see next comment)

> 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.

I always found it so odd that Ruby uses a special syntax for modules
and not just copy the beautiful solution Python has pioneered. Matz,
you already copied SOOO much, are you really trying to save face,
because it's far too late for that my friend!

> 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.

Python's way is better. There is no way to argue against it. Globals
are bad, redundant end statements are bad, TIMTOWTDI is bad, module
declarations are bad, not having docstrings is bad, allowing method
calls without parenthesis is bad, using punctuation in identifiers is
bad, bad keyword naming choices are bad, need i go on...?

I would say check out Ruby if no more than just out of curiosity. You
will find the map far more useful, and the linear chaining of methods
more natural, but after that there really ain't much more to
like! ...although i am sure the word "closure" is coming up *real*
soon!




More information about the Python-list mailing list