Python's simplicity philosophy

Dave Brueck dave at pythonapocrypha.com
Wed Nov 12 12:31:38 EST 2003


> On Wed, Nov 12, 2003 at 08:28:29AM +0000, Robin Becker wrote:
> > sequence.sum()
> > sequence.reduce(operator.add[,init])
> > sequence.filter(func) etc etc
> >
> > That would make these frighteningly incomprehensible ;)
> > concepts seem less like functional programming. Personally I wouldn't
> > like that to happen.
>
> I'm hoping you were being sarcastic ... but I get the feeling you aren't.
>
> Why, pray-tell, would you want an OO program to do:
>
> results = [ func(x) for x in sequence ]
>
> ... instead of ...
>
> results = sequence.map(func) ??

Because I find the first much more readable (and IMO the "an OO program to
do" bit is irrelevent from a practical point of view).

Also, someone not familiar with either version is likely to correctly guess
what the first one does. It's not an issue of whether or not a person can be
taught what 'map' means). It's subjective, yes, but not _completely_
subjective because the "guessability" of the first form is higher because it
uses other well-known keywords to do its thing. (FWIW I don't think map() is
that big of a deal, but you asked... :) ).

-Dave






More information about the Python-list mailing list