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

Heiko Wundram modelnine at modelnine.org
Wed Jul 30 09:03:49 CEST 2008


Am Mittwoch, 30. Juli 2008 08:30:48 schrieb Russ P.:
> On Jul 29, 11:09 pm, Erik Max Francis <m... at alcyone.com> wrote:
> > I'm getting this sneaking suspicion that you guys are all putting us on.
>
> As I said in an earlier post, I realize that this would only work if
> there were only one copy of "empty" (as there is only one copy of
> "None"). I don't know off hand if that is feasible or not.
>
> You reply reeks of the kind of pedantic snobbishness that makes me
> sick.

I can understand (and pretty much sympathise) that you get this kind of reply, 
simply because the point you and Carl Banks (formulated somewhat differently) 
put up has been answered again and again (in this thread), and I can only 
repeat it once more:

__nonzero__(), i.e. the "cast" to boolean, is THE WAY to test whether a 
container is empty or not. Like this design decision, or don't like it, but 
the discussion is not going to go anywhere unless you concede that there is a 
(very explicit!) way to test for non-emptiness of a container already, and 
you're currently simply discussing about adding/using syntactic sugar 
(different means of expressing the test) to suit your own personal taste 
better. Anyway, check the documentation for __nonzero__(): if the object 
doesn't implement that, but implements __len__(), the interpreter "replaces" 
the __nonzero__() test by __len__()>0, so I guess someone in the design 
department must've seen it logical for the truth value of a container to 
express the test "len(x)>0" at some point in time to make this interpretation 
for the truth value of a container.

There cannot be an argument about missing/misplaced functionality (that's what 
you make it sound like), if the functionality for doing what you want to do 
is there and you simply don't like the syntax, which I can somewhat relate to 
because style is a personal thing, even though I don't see either points made 
by you or Carl Banks, because implicit casting to bool is so common in pretty 
much every programming language to test for "truth" of an object, and IMHO 
it's completely logical to extend that idea to containers to mean 
empty/non-empty.

Eric Max Francis tried to explain why your syntactic "enhancement" would come 
at a much greater price than its worth, and he's absolutely right in that, as 
it's an abuse of the "is" operator, but again, that's a somewhat different 
point. It changes nothing about the fact that all this discussion centers 
around something that is a non-point, but simply a matter of personal taste.

-- 
Heiko Wundram



More information about the Python-list mailing list