Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old May 23rd, 2006, 9:16 AM   #11
hydroxide
Programmer
 
Join Date: Apr 2005
Posts: 73
Rep Power: 4 hydroxide is on a distinguished road
(Gnaaah... take two)
Quote:
Originally Posted by DaWei
It wasn't directed at you, Arevos, it was directed at the rewriting of my code...
I apologise for the overbrevity of my comment. As Arevos has suggested, when you compare None (and to a lesser extent True and False) by value (==, !=) rather than by identity (is, is not) you can end up with unexpected results if the object you're comparing is buggy, etc. It's not a common problem, but when it happens it can be painful to track down, so it's better to have the habit of always using identity comparison rather than value comparison even if the object (in this case the regex matches) is (almost) certain to be bugfree.

The following should illustrate:
class Expected:
    pass

class Evil1:
    def __eq__(self, other):
        return self == other

class Evil2:
    def __cmp__(self, other):
        if other is self:
            return True
        return False

for cls in (Expected, Evil1, Evil2):
    x = cls()
    print cls.__name__
    print "   ", x == None, x != None, x is None, x is not None, "\n"
-T.
"One man's cargo cult is another man's defensive."
hydroxide is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC