PEP 285: Adding a bool type

John Roth johnroth at ameritech.net
Sat Apr 6 21:30:53 EST 2002


"Laura Creighton" <lac at strakt.com> wrote in message
news:mailman.1018111094.10533.python-list at python.org...
> +>
> > "Alex Martelli" <aleax at aleax.it> wrote in message
> > news:gJDq8.55255$S52.1904212 at news2.tin.it...
> > > John Roth wrote:
> > >         ...
> > > > Maybe my post in response didn't propagate? As I said in that
> > > > post, the root of her problem is a poorly chosen name for the
> > > > function. If she paid attention to constructing the name
properly,
> > >
> > > She adopted the name *Guido* had given to the function right in
> > > his pep (actually clarifying it a bit from 'isleap' in his PEP
> > > to 'isLeapYear', more readable, in her post).
> >
> > Sorry I'm late in responding to both posts - I had a problem
> > with my newsgroup vendor and I'm just back on.
> >
> > I thought the original example was very bad, but I didn't
> > say so at the time because I hadn't figured out what I didn't
> > like about it.
> >
> > The original example was something like
> >
> > number of days in year = 365 + isLeap(year).
> >
> > To put it bluntly, that's a very confusing hack that depends
> > on conceptual True being 1 and conceptual False being
> > zero.
> >
> > Again, to put it very bluntly, Laura swallowed a camel
> > while straining at a gnat. She had a great deal to say about
> > the difficulty of teaching that example, and I agree completely.
> > It would be very difficult to teach, but the reason is that
> > the name is simply wrong. The fact that Guido himself
> > used that as an example doesn't make it right, either.
> >
> > If she had corrected the name, then her entire basis for
> > the objection would have evaporated.
> >
> > John Roth
> > >
> > >
> > > Alex
> > >
>
> Still haven't found the time to read my original post, notice that
> I _did_ correct the name in the original post, and understand what
> I was trying to say, I see.  I will correct your misconception
> because you might confuse somebody else.
>
> I am objecting to the fact that isleap, whatever the hell it is
> called, returns a boolean.  I am rejecting the existence of
> booleans in the language because it is too hard to teach how
> to use them properly.  Most people never learn.  Most code that
> uses booleans should not.
>
> Proper use of booleans requires not only that you have a
> function that returns one of two values, but THAT YOU NEVER
> EVER WANT THAT FUNCTION TO EVER BE MODIFIED TO RETURN ONE OF THREE,
> (or more).  What I tell my students is that you really want
> a hole to open in the ceiling and a Warner Brothers safe to fall
> on the head of somebody who attempts to extend, subclass, or
> in any other way change the function to return one of three values.

I understood your point the first time. I disagree with it. If you
want to change the definition of a function to do something else,
then you may well need to change the name. This is called
refactoring.

> And, by God, if the function that returns _the number of leap days
> in the year_ isn't safe, at 0 or 1, then damn near close to nothing
> that my students are going to be tempted to use 'True' and 'False'
> for is.  This example makes my course notes, under Why using booleans
> is bad, and you should never do it.  (unless you are a mathematician
> who wants to do real 2-valued algebra, or somebody interfacing with
> some other piece of software that needs those sort of bools, or
> some other, EXTREMELY RARE,  person.  Don't you guys interrupt here.
> This is hard enough to teach as it is.)
>
> It does not help that it appears to the outside that Guido just went
> through all the python functions that returned 1 or 0 and changed
> them to return True or False.  I know that Guido would not be
> so stupid, and that there is a reason why he wants, for instance,
> isinstance to return only 0 or 1 for evermore, but I can't see it.
> I would like an isinstance that returned 0 for not an instance of
> this class, 1 for a direct instance, and 2 for a subclass.  There
> must be a lot of code out there I have never seen that relies on
> this never happening, and now, alas, I have to find out why.
>
> Because my students will ask, of course.  If True and False are
> good enough for Guido, then it's good enough for them.  I would
> love it if a huge comment was added to python files that now
> return booleans saying why it was necessary to restrict the
> return values to one of 2 forever more, so people are not confused
> into thinking that returning booleans is a good idea in general,
> but that may be too much to ask for.  I would add the comments
> myself, but I am having problems seeing what the reasons are.
> Maybe after I get some more sleep, it will come clearer to me.
>
> I truly liked telling students, especailly ones that have never used
> Python while we are using some other language,   'You don't need
> True and False. Look at Python.'
>
> Now I have to say, to the students who are using
> Python: 'Python has True and False.  It is not for you little
>          worms, and if I catch you using it I will make you do
>          the assignment over.'
>
> I know in all the Python code I have ever written I have only 5 times
> wanted a boolean True or False -- all times when I was talking to a
> database that required it.  The rest of the time I wanted an integer,
> 0 or 1.  Even if I couldn't see a way that somebody was likely to
> extend it to return 3, there most certainly was never ever going to be
> any code that required that it only have one of 2 values, so now I
> will have to change all my True and False there to be 'Yes' or 'No' or
> something.  (grumble, now I wish I had lost the argument to the person
> who wanted the constants we picked to be TRUE and FALSE).
>
> Teaching people to not use booleans is hard.  They grab for them
> whenever they have a function that returns one of two values.  It
> was a lot easier to teach this concept when the fool things were not
in
> the language.
>
> Note:  don't tell me that because python bools are just ints, it
>        doesn't matter -- people who were using bools for
>        DEMOCRAT and REPUBLICAN can now add
>        THE_DAMN_VOTE_WASNT_PUNCHED_THROUGH - (the integer 3)
>        when to their horror they discover 2 values was not enough.
>        I need to teach students to not use bools in languages which
>        are not so forgiving.

Here I thought that teaching about bools was quite easy.
Bools answer a specific question: is it x? True or False.
They do not answer the question: which X is it?

In other words, bools select one possible case out of
however many there are; they are not a substitute for a
universe which has only two cases.

People who were using bools for your Democrat or Republican
example were simply using them incorrectly. In most states, there
were way more than two choices: the Green party got enough votes
to throw the election to Bush. If he hadn't run, Gore would have
won!

It may very well be that bools are overused. That doesn't mean
that they should never be used.

John Roth

>
> Laura Creighton
>
>





More information about the Python-list mailing list