__iadd__ and fellows missing (Python 2.2)

Mike C. Fletcher mcfletch at rogers.com
Sat Apr 13 18:11:48 EDT 2002


Using an unlikely-but-not-guaranteed static value such as "OpTioNaL ArG 
NoT GiVeN" for NULL makes the software's reaction dependent on the data 
it's processing (and the version of the interpreter it's running on (if 
you're  using is for comparisons), string-(or, apparently, 
tuple)-identity check is essentially a random/upredictable event).


Consider, for instance:

	an instance of a class that compares == to anything (will compare == to 
the string), so you need to use is for identity checking.

	objects that blow up when you access any attribute of them, or which take 
hours to access a given attribute (e.g. __cmp__)

	some evil user decides to put "OpTioNaL ArG NoT GiVeN" into the system, 
since the identity of that argument is entirely dependent on the 
interpreter (it may or may not be the same object as the default arg), 
you have a "random" reaction to the data.


Using a true singleton instance or even a list means that the system's 
operation is not dependent on the data at all (don't need to use ==, 
doesn't have a particular value that causes unexpected results).

Enjoy,
Mike

Terry Reedy wrote:
> "Mike C. Fletcher" <mcfletch at rogers.com> wrote in message
...
>>  Suppose I'll wind up using singleton instances instead.
> 
> 
> Given that None is a possible input, so it cannot be used as the
> no-input flag, you could also try something like NULL="OpTioNaL ArG
> NoT GiVeN"
> 
> Terry






More information about the Python-list mailing list