integer >= 1 == True and integer.0 == False is bad, bad, bad!!!

rantingrick rantingrick at gmail.com
Sun Jul 11 02:50:05 EDT 2010


On Jul 11, 1:22 am, Stephen Hansen <me+list/pyt... at ixokai.io> wrote:

> If you are so desperately concerned with space, then simply do:
>
>     if (choiceIdx1, choiceIdx2) != (None, None):
>
> Its only eleven characters longer.
>
> Or, you can do:
>
>     if None not in (choiceIdx1, choiceIdx2):


Only the first example was worse than the second. You do realize that
Python must build a tuple for ever conditional that uses this
semantic? This is more bad, bad, bad than integer bool-ing! My bin
packer could potentially compute millions of parts. I do not want to
waste valuable processor cycles building numerous tuples just for the
sake of a conditional "condition"! This is bad coding style Stephen.

> Its only two characters. You really can't honestly be making an argument
> about two characters.
>
> > If you *can* Stefen,
>
> My name is Stephen.

It was a typo not an on purpose misspelling

> Of course I won't offer that. If I wish a boolean flag, something which
> can have only one of two states (although sometimes a three-state
> 'maybe' is useful, with None being the 'neither true nor false'), I'd
> use the boolean.

I agree... True, False, None. The trinity of bool-inity.

> There's numerous cases where "if x" where x is an integer is useful. A
> counter is the simplest example. Say you're counting how many
> watermelons are in your inventory there is, and you want to test if
> there's any or not. "if watermelons" is the concise, readable,
> understandable way to express this. Readability counts.

I agree but when in a conditional bool(integer) should be forced.
Look, don't try to shoove this under the mattress like nobody
initializes a variable to None and then maybe or maybe not stores an
array index in the variable and then later needs to test for true
false in a conditional. It's very common to initialize a counter or
index variable to None or 0. And later you don't want 0 and None bool-
ing to False and range(1:infinity)+range(-infinity:-1) bool-ing to
True!

> A boolean test in Python tests "something" verses "nothing", it doesn't
> test Truth verses False
>
> It is entirely consistent in this regard (except in the case of custom
> classes which may decide to do strange things).
>
> Zero is, clearly, nothing.

No shit! i am talking about CONDITIONALS HERE. Specifically
CONDITIONALS and BOOL-ING!

> Utter nonsense. No one does that unless they are coming from C or some
> other language without a True/False and don't know about it, or if they
> are using a codebase which is supporting a very old version of Python
> before True or False were introduced.

Ah yes, when nothing else seems to work fall back to you default
programming... FUD and ad hominem
attacks

> But you're just going to argue endlessly, no doubt. Have you ever
> actually considered the fact that your gut reaction might, I don't know,
> be wrong or misguided? I've admitted when I'm wrong on more then one
> occasion.

I have no problem admitting when i wrong. In this case however i am
completely right. Use True/False for bool-ing, None for emptyness, and
integers for inetgers.



More information about the Python-list mailing list