[Python-ideas] Fwd: Null coalescing operator

Rob Cliffe rob.cliffe at btinternet.com
Tue Sep 13 07:15:00 EDT 2016


On 13/09/2016 04:43, Guido van Rossum wrote:
> On Mon, Sep 12, 2016 at 5:45 PM, Rob Cliffe <rob.cliffe at btinternet.com> wrote:
>>
>> On 12/09/2016 16:37, Guido van Rossum wrote:
>>> For the record, I still really don't like PEP 463. We should strive to
>>> catch fewer exceptions, not make it easier to catch them.
>> Can you please clarify what you are saying in the last sentence?
>> The first time I read it, my brain parsed it as "People should raise fewer
>> exceptions, i.e. use LBYL less".
> (If that means "Leap Before You Look", yes. :-)
I meant EAFP, but ! like your version! :-) Sorry for the confusion.
>
>> Later it seemed more likely that you meant "The set of exceptions we catch
>> in a specific piece of code should not be too large; we should only catch
>> those exceptions that we really mean to handle".
>> But perhaps you mean something else altogether?
>>
>> Also I don't see the connection between the first sentence and the second.
>> Exception-catching expressions as per PEP 463 just give you a more concise
>> way of of doing something you can do with try+except.  Do you mean it would
>> make it easier to catch exceptions because you have to type fewer
>> characters, and that this would be a bad thing?
> Yeah, that's exactly my point. PEP 463 gives you a shorter way to
> catch an exception, so it gives you less motivation to find a way to
> write your code (or define your API) that doesn't involve catching
> exceptions. But APIs involving exceptions are often inferior to APIs
> that don't require exception catching. (Yes, I am aware of __next__()
> raising StopIteration -- but that API design usually doesn't require
> you to catch it.)
>
You surprise me.  I thought LBYL and EAFP were both approved Python 
idioms, in some cases one being better, in some cases another, choice to 
be made on the merits of each case (or the author's preference).  I 
certainly use both (and sometimes time both to see which is faster).
Now it sounds as if you're trying to impose a style guide on the world 
by discouraging the EAFP.  And wasn't the discussion general, not about 
APIs specifically?
Best wishes,
Rob Cliffe


More information about the Python-ideas mailing list