PEP 285: Adding a bool type
Mark McEahern
marklists at mceahern.com
Sat Apr 6 14:06:01 EST 2002
[Laura Creighton]
> My pleasure, especially since this is such a cool example. You have
> just shot yourself in the foot, and do not know it. When you have
> shipped your isValid function, across the world to your 10,000 clients,
> you will discover this.
>
> Your boss comes in and says, oh, Mark, we need a change to that
> isValid function. We need to return 3 states, Valid, Invalid, and
> Valid-but-You-Don't-Have-Access-Because-You-Didn't-Pay-Your-Bill.
>
> What do you do now?
Get a different job? ;-)
Seriously, if my boss knows which functions need to change and how, what am
I there for?
So let's say I start off with this function:
def getValidity(user, password):
return someInt
Now, I add a new return value to it for this new scenario. I still have to
change the code that calls this function because it didn't previously know
about the new return value.
What have I gained aside from a useless rule that seems to promise me
use-me-and-you-won't-need-to-change-stuff, but can't really deliver?
Or maybe you're saying I'll have to change LESS stuff. I don't think that's
what you're saying, else you'd have said it. ;-)
I must confess, this feels like a shell game. You want to deny the obvious
fact that at some point in my code I need to know whether the user's
password matches. And it quite clearly either matches or it doesn't. I
spell that boolean, I don't know about you.
You seem to be saying, "You *think* that's what you want, but later on you
might want other things." Fine, I concede that point. I'll cross that
bridge when I get to it. I don't see how trying to cross it now--especially
when I have no clue as to the particular vector of change--is going to do me
any good.
If there's other stuff I need to do, I can easily write other code to do it.
And it may mean replacing or refactoring existing code. Big deal. Where's
the problem? I just don't see the problem. Much less the supposed
solution.
As you said, change is inevitable. I don't have a problem with that. I
still don't see what's wrong with using booleans.
> Do you now? Use Booleans when you want to return ON and OFF -- the
> state of that bit in memory, of something that is constrained by
> physical reality, or mathematical reality to only have 2 values, ever,
> cross my heart and the world will end if this ever ceases to be the
> case.
Such as whether the user's password is correct or not?
> Don't artificially limit yourself to 2 values because your
> vision at the time only extended to 2 values. The one thing constant
> in this world is change. If you don't need a third value, somebody
> else will, later. Integers are your friends.
I'd say, don't artificially try to defer everything when your solution is
staring you in the face.
// mark
More information about the Python-list
mailing list