Graceful detection of EOF
zanesdad at bellsouth.net
Fri Oct 8 14:05:48 CEST 2004
Alex Martelli wrote:
>Jeremy Jones <zanesdad at bellsouth.net> wrote:
>>>This is well in line with the normal Python idiom,
>>>as compared to "look before you leap".
>>> dalke at dalkescientific.com
>>So, what you're saying is that the Python way, in contradistinction to
>>"look before you leap", is "land in it, then wipe it off?" Can we get
>>that in the Zen of Python? :-)
>The "normal Python idiom" is often called, in honor and memory of
>Admiral Grace Murray-Hopper (arguably the most significant woman in the
>history of programming languages to this time), "it's Easier to Ask
>Forgiveness than Permission" (EAFP, vs the LBYL alternative). This
>motto has been attributed to many, but Ms Hopper was undoubtedly the
>first one to use it reportedly and in our field.
>In the general case, trying to ascertain that an operation will succeed
>before attempting the operation has many problems. Often you end up
>repeating the same steps between the ascertaining and the actual usage,
>which offends the "Once and Only Once" principle as well as slowing
>things down. Sometimes you cannot ensure that the ascertaining and the
>operating pertain to exactly the same thing -- the world can have
>changed in-between, or the code might present subtle differences between
>the two cases.
>In contrast, if a failed attempt can be guaranteed to not alter
>persistent state and only result in an easily catchable exception, EAFP
>can better deliver on its name. In terms of your analogy, there's
>nothing to "wipe off" -- if the leap "misfires", no damage is done.
Eloquently stated, as usual, Alex. I hope that you didn't take me
seriously, though, and that your (excellent) explanation was for the
benefit of all readers to provide us all with a snippet of pragmatic
thought and a good thought pattern to approach a lot of problems with.
Of course there is nothing to "wipe off." It was a joke I had hoped
would be made evident by my little emoticon ":-)". But again, excellent
codification of what may be in a lot of us merely an intuitive approach
and less well internally described as what you've stated above. Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list