On 5/23/2011 4:49 AM, Octavian Rasnita wrote:
But let's remember from what this discussion started. This is not a
Python critique, because each language has its own ways.
I just wanted to show that the fact that "there is more than one way to
do it" in Perl and that "there is a single way" in Python are just
buzzwords,
Agreed. The latter is simply incorrect for Python and I don't know why
people say that. The statement from the Zen of Python is as follows:
"There should be one-- and preferably only one --obvious way to do it."
where 'it' is some reasonable common operation. This is a statement of
*intent* that is opposed to "All possible ways of doing things should be
included". The key word that people too often omit is *obvious* (once
one learns Python). There are usually, of necessity, multiple ways to do
something, but for common operations, there should be one way that is
obvious to the experienced Python programmer.
For instance, if you want to process the items of a collections, you can
use normal recursion, tail recursion, while iteration, or for iteration.
For the first three, you can use explicit or implicit conditions for
flow control. (Implicit conditions are by try-except.) One can use
various access methods to get the items. However, the one obvious,
compact, and efficient way is 'for item in collection:'. This works with
*any* collection with a proper __iter__ method.\
People accustomed to using tail recursion for this in other languages
sometimes request that tail-call space optimization be added to make
tail recursion a second 'obvious' way. Guido has refused because 1)
there are real problems with the idea and 2) one obvious way is enough.
Similarly, the obvious way to define a function is a def statement. One
alternative, which Guido allowed to be added for the specific purpose of
passing simple functions as arguments in function calls, is a lambda
expression. Guido has rejected requests to expand lambda expressions to
general function definitions. Again, there are real problems and one
obvious way is enough.
> because this was an example where in Python there are many
ways to do it while in Perl there is a single way used usually, which is
also more simple.
Here I disagree. As I replied before, you are either ignoring the
obvious Python way or talking about a rare need.
--
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list