DIP 1002 (TryElseExpression) added to the queue
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Wed Sep 28 03:45:11 PDT 2016
On 9/28/16 12:19 PM, Jack Stouffer wrote:
> On Tuesday, 27 September 2016 at 09:30:10 UTC, Dicebot wrote:
>> https://github.com/dlang/DIPs/blob/master/DIPs/DIP1002.md
>>
>> PR: https://github.com/dlang/DIPs/pull/43
>>
>> Abstract:
>>
>> In Python, the try/catch/finally syntax is augmented with an
>> additional clause, termed else. It is a fantastically useful addition
>> to the conventional syntax. It works like this:
>
> I support this addition because, while it's possible to mimic this
> behavior now, this makes code cleaner.
This rough count:
git grep '^ *try' | wc -l
reveals 187 uses of "try" in Phobos. Of these, how many could be
improved? Looking into that and also on a selection of dub projects
would strengthen the argument. Assertions such as "makes the code
cleaner" are likely to add value only if backed up by evidence (case
studies, realistic examples).
> I will also post some rationale from the Python docs:
>
> "The use of the else clause is better than adding additional code to the
> try clause because it avoids accidentally catching an exception that
> wasn’t raised by the code being protected by the try/except statement."
>
> https://docs.python.org/3/tutorial/errors.html#handling-exceptions
Porting motivating arguments from other languages is helpful only if put
in the context of D, e.g. Python does not have "scope" statements, which
makes matters different across the two languages.
Andrei
More information about the Digitalmars-d
mailing list