Confessions of a Python fanboy

Jan Kaliszewski zuo at chopin.edu.pl
Thu Jul 30 23:52:45 CEST 2009


Dnia 30-07-2009 o 22:41:57 Masklinn <masklinn at masklinn.net> napisał(a):

> On 30 Jul 2009, at 22:23 , Jan Kaliszewski wrote:
>> 30-07-2009 o 13:36:49 Masklinn <masklinn at masklinn.net> wrote:
>>
>>> On 30 Jul 2009, at 06:04 , alex23 wrote:
>>>> On Jul 30, 1:06 pm, r <rt8... at gmail.com> wrote:
>>>>> 2.) the .each method
>>>>> container.each{|localVar| block}
>>>>> This method can really cleanup some ugly for loops, although i really
>>>>> like the readability of for loops.
>>>>
>>>> map(lambda localVar: <block>, sequence)
>>>>
>>>> or:
>>>>
>>>> def usefully_named_func(var):
>>>>   <block>
>>>>   return var
>>>>
>>>> transformed = [usefully_named_func(v) for v in sequence]
>>>>
>>> The issue here is of course that `map` and comprehensions are  
>>> transformations. `#each` exists for effectful iterations (Ruby has  
>>> `#map` for the map operation). So the intent expressed by `#each` and  
>>> `map` isn't the same. Furthermore and this is the most problematic  
>>> limitation of Python here, `lambda` doesn't allow complex  
>>> transformations due to its restrictions, so one has to switch to named  
>>> functions which works but isn't sexy (and tends to lower readability  
>>> imo).
>>
>> I don't see any real limitation. What's wrong in:
>>
>> for localVar in container:
>>    block
>>
> Well what's wrong with using that rather than `map`, `filter` or a list  
> comprehension? (and if you don't see what the limitations of `lambda`  
> are, you probably very rarely use it)

I know well about the expression-only-limitation of lambda, fortnately
there is the 'for' loop construct (or, alternatively, you can define
a named function).

And then, what's wrong with using 'for' rather than 'map', 'filter' etc.?
Agree, that 'anonymous block syntax' would be nice in some cases, but
I don't see any real limitation caused by lack of it i.e. something you
can't (all you can only with unreasonable effort).

>> And ruby's container.each is very similar to Python's iter()

> Uh… not at all…

OK, .each is like Python's iter() + some form of iterating over it
('for' loop or '[i]map'...).

Still, in this matter there is no real functionality in Ruby that you
can't reach in Python.

All that confessions of a (former?) Python fanboy are about sintactic
sugars, which importance is incomparable which such issues as e.g.
particular mechanism of classes, their inheritance etc. or even such
small helpers like function annotations.

Cheers,

*j

-- 
Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>



More information about the Python-list mailing list