Express What, not How.
luke at bluetail.com
Thu Oct 16 13:09:57 CEST 2003
ketil+news at ii.uib.no writes:
> Anonymous functions *can* be more clear than any name. Either because
> they are short and simple, because it is hard to come up with a good
> name, and/or becuase they are ambigous.
> Say I want to attach an index to elements of a list. I could write
> integers = [1..]
> attach_index ls = zip integers ls
> or just
> attach_index ls = zip [1..] ls
If we're arguing to eliminate names that don't say very much, then
attach_index = zip [1..]
> Whether you want to give an explicit name to the list of integers is
> not given. If the indexed list is local, it is better to use the
> definition directly; I don't want to look up the definition of
> integers (perhaps in a different module) to check whether it is [1..]
> or [0..].
And for the exact same reason you might like to just write "zip [1..]"
instead of using a separate "attach_index" function.
More information about the Python-list