Re: True inconsistency in Python
From: Erik Max Francis (max_at_alcyone.com)
Date: 11/18/03
- Next message: Erik Max Francis: "Re: True inconsistency in Python"
- Previous message: Bengt Richter: "Re: PEP 321: Date/Time Parsing and Formatting"
- In reply to: KefX: "Re: True inconsistency in Python"
- Next in thread: Terry Reedy: "Re: True inconsistency in Python"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 17 Nov 2003 18:35:59 -0800
KefX wrote:
> What if the expression is 37 lines long? (Can't happen? I'm LOOKING at
> such an
> example!) Fishing out the main comparison in such a monster isn't
> always the
> easiest thing to do. Of course I'm exaggerating here, since we usually
> don't
> write 37-line expressions, but still.
What if it's twenty pages long? I still don't see the benefit. If
you're looking at an expression in an if statement, you need to look at
the _whole_ expression to figure out what it's doing. I don't see how
ending it with `== True' makes it any more readable.
> Yes, all tests are boolean tests in the sense that they evaluate to a
> bool and
> the if statement then compares the result, but not all comparisons are
> boolean
> comparisons in the sense that we don't always compare to a boolean
> value. In
> other words, "a == 0" isn't comparing against true or false, it's
> comparing
> against an integer. It's worth noting here that omitting the "== 0"
> here is
> considered bad style by many (though this is by no means universal).
Well, if you leave off the `== 0', it means something else.
> The camp
> that would have you write "== false" invariably falls in the same camp
> that
> would have you write "== 0", because that way the two would be
> consistent in
> that you always specify what's being compared to what.
Not even a little. An explicit test for an individual value is one
thing. An explicit comparison for an individual value _when there are
only two possible categories_ (true or false) is utterly pointless,
because all it does is add the opportunity to create an error.
> Of course, this
> doesn't
> mean everybody would have you write "== 0" would also have you write
> "==
> false". The idea is consistency (I don't know how that slipped my mind
> in my
> original posting.)
It's not at all consistent, that's the problem. Not to mention the
fact, as others pointed out, that not all false values are False.
> I don't see how that would logically follow just from making an
> explicit bool
> test.
Because in Python the explicit Boolean test cannot possibly be anything
other than redundant. If it is not redundant, it is probably an error.
-- Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/ __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE / \ \__/ So little time, so little to do. -- Oscar Levant
- Next message: Erik Max Francis: "Re: True inconsistency in Python"
- Previous message: Bengt Richter: "Re: PEP 321: Date/Time Parsing and Formatting"
- In reply to: KefX: "Re: True inconsistency in Python"
- Next in thread: Terry Reedy: "Re: True inconsistency in Python"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|