ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: Good code patterns in Python
by Lulu of the Lotus-Eaters other posts by this author
Jul 1 2003 6:26PM messages near this date
Re: Good code patterns in Python | Re: Good code patterns in Python
|hwlgw@[...].com (Will Stuyvesant) wrote:
|>      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

mis6@[...].edu (Michele Simionato) wrote previously:
|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.

Moreover, actual code often assigns from computations, not simply one
name to another.  The harder-to-read form risks bad side effects (or
simply a performance hit):

    some_name = some_computation()
    if not some_condition:
        some_name = other_computation()

The straightforward if/else form avoids superfluous computations.

Yours, Lulu...

--
 mertz@   _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i
gnosis  _/_/                    Postmodern Enterprises         _/_/  s r
.cx    _/_/  MAKERS OF CHAOS....                              _/_/   i u
      _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/    g s


-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Will Stuyvesant
Ben Finney
Erik Max Francis
Bernhard Herzog
holger krekel
Kirk Job-Sluder
Erik Max Francis
Dennis Lee Bieber
Jiri Barton
Lulu of the Lotus-Eaters
Terry Reedy
Steven Taschuk
Michele Simionato

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved