Boolean tests [was Re: Attack a sacred Python Cow]
pavlovevidence at gmail.com
Thu Jul 31 04:00:18 CEST 2008
On Jul 30, 4:49 am, Ethan Furman <et... at stoneleaf.us> wrote:
> Carl Banks wrote:
> > On Jul 29, 6:42 pm, Matthew Fitzgibbons <eles... at nienna.org> wrote:
> >> I don't have any postable code (it's in a half way state and I haven't
> >> touched it for a while), but I'll see if I can't find the time to bang
> >> something up to give you the gist.
> > I wouldn't bother at this point. I was looking to see if someone
> > could come up with something to disprove my belief on the polymorphic
> > uselessness of "if x" relative to explicit tests, and if (as I
> > anticipated) they did not, I could claim that "if x" is really just a
> > glorified keystroke saver. But I now realize that the failure of this
> > bunch doesn't prove anything. I don't think most people even realize
> > why answering the question I asked would demonstrate the usefulness of
> > "if x".
> > Your example isn't exactly the smoking gun I was looking for, but I
> > guess we'll have to admit that at least one usage will suffer for not
> > having it.
> > Carl Banks
> Even for those that did realize, and in fact hoped that that is what you
> were attempting to accomplish,
I was not attempting to accomplish what you think I was.
I was looking for it, but I didn't want to see it. I didn't expect to
see it. I wanted to show that "if x" doesn't have the polymorphic
advantage people mindlessly claim it does by posing the challenge and
having people fail to meet it, and for the most part the examples that
met the challenge were for minor usages. Ok, someone wrote a filter
that truly benefits from polymorphism of "if x" against very different
types, but really, these use cases aren't all that common.
It's not like it's an everyday thing for you to write "if x" instead
of "if x!=0", and that it actually saves you from having to rewrite
the condition because later you decided to use a list.
So I stand by the point I was trying to make: for your average day-to-
day programming, the main benefit of "if x" is to save keystrokes. It
doesn't help your code become more polymophic in practice. A little
more polymorphic, yes. A lot, no.
> it was still quite frustrating to see you
> ignoring all the non-code, yet perfectly valid examples of why "if x"
> was not only valid, but the most pythonic way to get the task done.
Pfft. The usage of "if x" might be Pythonic, but I think the best way
is the way Java does it.
> I think it would have been a better discussion if you had responded with
> reasons why, and not just parroted the "show me the code!" line over and
> over and over and ... It seemed as if you thought you were the
> professor, impatiently trying to teach a class full of idiots by playing
> the devil's advocate.
I wasn't playing Devil's advocate, I was playing the Devil. That's
why I did that. Sorry if it irritated people but I wasn't about to
those things distract me.
> I was sure hoping someone would get the actual
> code example and post it, partly because I enjoy learning, but mostly
> because it would (hopefully) shut you up and move the conversation
> along. In fact, somebody did post some code about a custom matrix
> class, where __len__ was useless, and still you kept on with... pah.
I admit it! I downplay even successful examples because I just don't
like implicit booleans. What can I say, I'm an optimist.
I didn't see any custom matrix class, BTW. The only code I saw was
Steven D'Aprano filter which he still apparently expects me to take
his word for it that the alternative I proposed won't work, and Terry
Reedy's empty-enabled iterator. Oh, also Heiko Wundram's integer set.
> It's late, so before I say something stupid I'll finish this. My last
> thought on the matter -- up until this thread I had looked forward to
> your posts, Carl. I think you did more damage than good to yourself
> with this stunt.
Sorry, but I must go on a crusade every once in awhile, whatever
damage it may cause my esteem. It's in my nature.
More information about the Python-list