Boolean tests [was Re: Attack a sacred Python Cow]

Ethan Furman ethan at stoneleaf.us
Wed Jul 30 05:17:56 EDT 2008


Russ P. wrote:
> Oh, Lordy. I understand perfectly well how boolean tests, __len__, and
> __nonzero__ work in Python. It's very basic stuff. You can quit
> patronizing me (and Carl too, I'm sure).
> 
> The point that you seem to be missing, or refuse to acknowledge for
> some reason, is that  "if x" can be mistakenly applied to any object
> when the programmer thinks that x is a list -- and the programmer will
> receive no feedback on the error.

You know... or maybe you don't, since you did just say what you just 
said... that is such a ridiculous point it only barely qualifies as 
deserving comment.  Rather than be really rude, I'll just say:  test 
it's type() if the function is that specific, or your code that brittle. 
  Python is not there to catch your logic mistakes, that's up to you.

> I have made errors like that, and I could have saved some time had I
> used an "empty" method that only applies to a list or other sequence.
> 
> Is that an important issue? I don't know. I'm not claiming it is. But
> you cannot just sweep it away as nothing.

I don't sweep it away as nothing -- I sweep it away as stupid.  The 
programmer is responsible for his (or her) program.  An analogy would be 
a driver and a car -- if the driver cannot handle the power and speed of 
a fancy car (python :), then the driver should get a different car 
better matched to his abilities.  It's not up to the car to say "oh, the 
speed limit is 50 here, I better apply the brakes for the driver."

~Ethan~



More information about the Python-list mailing list