![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
Programmer
Join Date: Apr 2005
Posts: 73
Rep Power: 4
![]() |
(Gnaaah... take two)
Quote:
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""One man's cargo cult is another man's defensive." |
|
|
|
|
|
|
#12 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Perhaps I oversimplify things. Rather than create examples, I reasoned thusly: Suppose I have two things that, compared as objects, yield one result. When compared by some attribute, they yield the opposite result. One of the two comparisons is "wrong." Which one is wrong depends on the requirements of the writer. The important thing, to me, is to be aware that there's a difference. I WAS NOT AWARE until the comment was made. I thank you for that and for your additional explanation. I will, I must admit, not ascribe evil or safety to one over the other, except as individual circumstance dictates.
I appreciate the help from both of you.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#13 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Assuming the code is correct, my measure of acceptable Python brevity is:
1) Let one of your peers look at it, and see if he/she can figure out how it works (in less than a day). 2) Imagine yourself looking at it after a few months and still know what it does. Lastly, you can play innocent, put the code on the forum, and ask how it works. If nobody answers, you exceeded the brevity limit! DaWei, may you be smitten with Python desire real good!
__________________
I looked it up on the Intergnats! Last edited by Dietrich; May 23rd, 2006 at 12:16 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|