Confessions of a Python fanboy

Masklinn masklinn at masklinn.net
Thu Jul 30 13:15:14 EDT 2009


On 30 Jul 2009, at 19:01 , Inky 788 wrote:
> On Jul 30, 12:04 am, alex23 <wuwe... at gmail.com> wrote:
>> On Jul 30, 1:06 pm, r <rt8... at gmail.com> wrote:
>>
>>> 1.) No need to use "()" to call a function with no arguments.
>>> Python --> "obj.m2().m3()" --ugly
>>>   Ruby --> "obj.m1.m2.m3"  -- sweeet!
>>> Man, i must admit i really like this, and your code will look so  
>>> much
>>> cleaner.
>>
>> How do you distinguish between calling a method with no arguments,  
>> and
>> getting access to the method object itself (because it _is_ an  
>> object,
>> y'know, it's OO all the way down...)?
>
> I agree with alex here. Will take the explicit syntax over the extra
> cognitive load of figuring out exactly what's going on with
> `obj.m1.m2.m3`.
There's no cognitive load whatsoever: it's calling methods. Always.  
Ruby simply gives you no other option. Now it could be very simple  
methods to instance attributes, akin to a java getter, but it's still  
only methods.

Furthermore Ruby has a pretty nice convention (sadly not used enough I  
think) taken from Scheme where it's possible to postfix a method name  
with "!" (note: the "!" is part of the name, there's no magic) to  
indicate that this method modifies the object it's called on rather  
than simply returning stuff.




More information about the Python-list mailing list