On Sun, 05 Jan 2014 20:24:53 -0000, Göktuğ Kayaalp <s...@gkayaalp.com> wrote:

AFAIK, we do not have "postfix conditionals" in Python, i.e. a condition appended to a statement, which determines whether the statement runs or not:

   py> for i in [False]:
   ...     break if not i

 The above piece of code is equivalent to this in Python:

   py> for i in [False]:
   ...    if not i
   ...        break

I believe that the first example is superior to the second example when the two is compared for readability and intuitiveness.

In my past life as a newcomer to Perl, I thought this too. Postfix conditionals read more like English, so they would be easier to take in and understand. As I wrote more code, I discovered that this didn't seem to be the case; except in very simple cases, I had to mentally transpose the conditional back to the start of the statement to properly comprehend what was going on and what the results would be for my sample data.

It looks like a good idea, but I don't think it works that well in practice.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to