Good code patterns in Python
Michele Simionato
mis6 at pitt.edu
Tue Jul 1 09:28:47 EDT 2003
hwlgw at hotmail.com (Will Stuyvesant) wrote in message news:<cb035744.0307010149.399df2eb at posting.google.com>...
> If you know that your source code is going to be used
> later by others, then I feel that code with the pattern:
>
> if some_condition:
> some_name = some_value
> else:
> some_name = other_value
>
> is often a mistake. Much better, safer, would be:
>
> some_name = some_value
> if not some_condition:
> some_name = other_value
I am sorry, but I feel that the first form is MUCH more readable than the
second one; the first form is crystal clear to me, whereas I must read
the second form two or three times to understand what it is going on.
I would never follow "guidestyles" suggesting the second one!
I only miss a ternary operator ... ;)
Michele
More information about the Python-list
mailing list