[Python-Dev] PEP 246, redux
Ian Bicking
ianb at colorstudy.com
Thu Jan 13 04:50:14 CET 2005
Phillip J. Eby wrote:
> At 04:07 PM 1/12/05 -0600, Ian Bicking wrote:
>
>> It also seems quite reasonable and unambiguous that a path object
>> could be adapted to a IReadableFile by opening the file at the given
>> path.
>
>
> Not if you think of adaptation as an "as-a" relationship, like using a
> screwdriver "as a" hammer (really an IPounderOfNails, or some such). It
> makes no sense to use a path "as a" readable file, so this particular
> adaptation is bogus.
I started to realize that in a now-aborted reply to Steven, when my
defense of the path->IReadableFile adaptation started making less sense.
It's *still* not intuitively incorrect to me, but there's a couple
things I can think of...
(a) After you adapted the path to the file, and have a side-effect of
opening a file, it's unclear who is responsible for closing it.
(b) The file object clearly has state the path object doesn't have, like
a file position.
(c) You can't go adapting the path object to a file whenever you
wanted, because of those side effects.
So those are some more practical reasons that it *now* seems bad to me,
but that wasn't my immediate intuition, and I could have happily written
out all the necessary code without countering that intuition. In fact,
I've misused adaptation before (I think) though in different ways, and
it those mistakes haven't particularly improved my intuition on the
matter. If you can't learn from mistakes, how can you learn?
One way is with principles and rules, even if they are flawed or
incomplete. Perhaps avoiding adaptation diamonds is one such rule; it
may not be necessarily and absolutely a bad thing that there is a
diamond, but it is often enough a sign of problems elsewhere that it may
be best to internalize that belief anyway. Avoiding diamonds alone
isn't enough of a rule, but maybe it's a start.
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Python-Dev
mailing list