Why I chose Python over Ruby

Marcin Mielżyński lopexx at autograf.pl
Sun Mar 5 23:27:21 CET 2006


Francois wrote:
> I discovered Python a few months ago and soon decided to invest time in
> learning it well. While surfing the net for Python, I also saw the hype
> over Ruby and tried to find out more about it, before I definitely
> embarked on studying and practicing Python. I recently found two
> sufficient answers for choosing Python - which is a personal choice and
> others may differ, but I'd like to share it anyway :

I use both Python and Ruby and I think You are a little bit unfair in 
your judgements.


> 
> 1) In Ruby there is a risk of "Variable/Method Ambiguity" when calling
> a method with no parameters without using () :

> 
> def a
>   print "Function 'a' called\n"
>   99
> end
> 
> for i in 1..2
>   if i == 2
>     print "a=", a, "\n"
>   else
>     a = 1
>     print "a=", a, "\n"
>   end
> end
> 
> OUTPUTS >>
> 
> a=1
> Function 'a' called
> a=99
> 

Yes, I agree with that, but being aware of that I have never had any 
problems. And this problem a arises only in method bodies. When a 
receiver is specified, there is no ambiguousity (Ruby objects dont have 
public fields)

> 
> 2) Ruby does not have true first-class functions living in the same
> namespace as other variables while Python does :
> 

Wrong! Ruby has first class functions and unlike Python Ruby supports 
_true_ closures (Python supports only readonly closures). The first 
class Ruby functions are the _blocks_.

> In Python :
> 
> def sayHello (name) :
>   return "Hello " + name
> print sayHello("Mr. Bond")
> m = sayHello
> print m
> print m("Miss Moneypenny")
> 
> OUTPUTS >>
> 
> Hello Mr. Bond
> <function sayHello at 0x0102E870>
> Hello Miss Moneypenny
> 
> In Ruby you need extra syntax that ruins the "first-class-ness" :

No, blocks again...

> 
> def sayHello (name)
>   return "Hello " + name
> end
> puts sayHello("Mr. Bond")
> m = Class.method(:sayHello)
> puts m
> puts m.call("Miss Moneypenny")
> 
> OUTPUTS >>
> 
> Hello Mr. Bond
> #<Method: Class(Object)#sayHello>
> Hello Miss Moneypenny
> 
> 4) Conclusion
> 
> Since I did a lot of work in Scheme, rigor and consistency are most
> important to me, and Python certainly meets this requirement.
> 
> --- Python newbie
> 

Depends, I like Pythons constructs consistency, but I also like Rubys 
object model constency

lopex



More information about the Python-list mailing list