a Python person's experience with Ruby

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sun Dec 9 16:59:07 EST 2007


Steve Howell a écrit :
(snip)
> 
> Jordan and others, thanks for all your posts; I am
> learning a lot about both languages.
> 
> This is what I've gathered so far.
> 
> Python philosophy:
>    passing around references to methods should be
> natural (i.e. my_binary_op = math.add)
>    calling methods should be explicit (use parens)
>    the use of setters/getters varies among Python
> programmers; properties, decorators, special methods,
> etc. can be used judiciously to affect the interface

You can forget decorators here - the examples in this thread were mostly 
tricky ways to define properties. To be more general, the Python way to 
implement transparent computed attributes is to hook into the lookup 
mechanism, usually thru the descriptor protocol (the property class 
being one possible implementation), but also using the __getattr__ / 
__getattribute / __setattr__ hooks.

> Ruby philosophy:
>    a method itself should be callable without parens
>    you can get a reference to a chunk of code, but
> then you need a little extra syntax, beyond just a
> variable name and parens, to eventually call it
> (yield, &, call, etc.)
>    when referring to methods, you can use :symbols to
> name the method you're interested in without actually
> calling it
> 
> My personal experience:
> 
(snip)
 >
>    I was surprised in Ruby by how seldom I really pass
> references to methods around,

This probably has to do with this nice feature named 'blocks' !-)

> but it is definitely
> something I want to understand better.
> 



More information about the Python-list mailing list