[Python-Dev] type categories
Sat, 17 Aug 2002 16:00:12 -0400 (EDT)
ark> Well, I started by talking about type categories and ways of
ark> writing programs that tested them. Dave Abrahams said, in
ark> effect, that I was really just talking about multimethods. I'm
ark> still not convinced.
David> Huh? That's certainly not what I thought I was saying. I was
David> saying that a reason I thought it was important to be able to
David> test type categories (what Guido calls "look before you leap")
David> was for implementing multiple dispatch. In other words, an
David> idiom which most people agree is usually a bad choice for user
David> code might be a great choice for a generalized library or
David> language facility.
David> It's pretty hard to see how you could construe my remarks as
David> asserting some interpretation of what you were saying.
It sure looked that way to me.
In any event, I can think of other contexts in which LBYL can be
useful. To go back to Guido's example, I agree completely that
testing whether a file exists, and then opening it in a separate
operation, is a bad idea. One reason is that by the time you get
around to opening the file, it may no longer exist, so the open
has to test anyway.
On the other hand, it does make sense to test whether what you have is
a valid file name as soon as you know that you are going to open the
file, even if you aren't going to open it for a while. The principle
here is that when failure is certain, failing early is usually better
than failing late.