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 >> wxpython-users
wxpython-users
Re: [wxpython-users] Re: has_key() method versus the 'in' statement
by Andrea Gavana other posts by this author
May 8 2008 1:35AM messages near this date
[wxpython-users] Re: has_key() method versus the 'in' statement | Re: [wxpython-users] Re: has_key() method versus the 'in' statement
On Thu, May 8, 2008 at 1:42 AM, Grant Edwards wrote:
>  On 2008-05-07, Chester <wxpythoner@[...].com> wrote:
> 
> 
>  > if my_dictionary.has_key("orange"):                      UGLY
> 
>  I disagree.
> 
>  > if "orange" in my_dictionary:                                 CLEAN
> 
>  I disagree.
> 
>  In the first example it is obvious to the reader that you're
>  checking to see if my_dictionary contains "orange" as a key.
>  In the second example it is not obvious whether the code is
>  checking whether my_dictionary contains "orange" as a key or as
>  a value.
> 
>  I find the first version more obvious.

And, moreover, if you don't know that my_dictionary is a dictionary,
the "in" statement can be misleading, as it applied to lists too (and
tuples and possibly other things). If the dictionary is called
dataValues, for example, what are you going to understand if you read
something like:

if "orange" in dataValues:

? If the code is not from you and it's not adequately commented, you
have to go wandering around to find what the hell dataValues is. So,
the has_key is going to disappear in 3.0: of all the changes the BDFL
and the board of gurus could have implemented this is possibly the
least interesting, least useful and least "code-cleaning-oriented" one
they could think of.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
_______________________________________________
wxpython-users mailing list
wxpython-users@[...].org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Thread:
Grant Edwards
Andrea Gavana
Raffaello
Andrea Gavana
Chester
Robin Dunn
Peter Damoc
Ft
Paul McNett
Werner F. Bruhin
Raph
Mike Driscoll

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