Alternatives to exceptions for error handling
Vladimir Panteleev
thecybershadow.lists at gmail.com
Mon Nov 23 02:14:33 UTC 2020
On Sunday, 22 November 2020 at 18:21:44 UTC, Paul Backus wrote:
> The biggest blocker for this is that D currently has no
> equivalent of Rust's `#[must_use]` and C++'s `[[nodiscard]]`. I
> have a DIP in the works to address this:
>
> https://github.com/dlang/DIPs/pull/193
This is great to see. Thank you for working on this.
Another approach that I'm not sure we've explored fully is to
outright deprecate silently discarding all function return
values. Functions which return a value that is only sometimes
useful seem like a relatively rare oddity. I took a stab at
implementing this as a DScanner check earlier this year:
https://github.com/dlang-community/D-Scanner/pull/819
Perhaps the most interesting product of the above is seeing what
things were affected in Phobos. Most occurrences were in unit
tests, which is understandable, and said breakages are probably
more tolerable. Some valid patterns were affected though, such as
returning `this` (as in the builder pattern). Perhaps it would
make more sense to instead allow annotating functions as that
it's safe to discard their return value (@discardable or such)?
More information about the Digitalmars-d
mailing list