Trying to use Mir ion, its a perfect example of the failure of D's attribute system
Paul Backus
snarwin at gmail.com
Thu Jan 19 04:36:00 UTC 2023
On Thursday, 19 January 2023 at 04:06:27 UTC, A moo person wrote:
> If the argument is that the library should have been designed
> to infer the annotations, then why even have the annotations in
> the language at all if the best practice is to infer them.
In principle, the annotations are there mainly for (a) cases
where attributes can't be inferred (e.g., extern functions), and
(b) cases where you want to override attribute inference (e.g.,
@trusted).
Unfortunately, the compiler does not do as much inference as it
could (e.g., it does not do inference for most ordinary
non-template functions), which leads some D programmers to adopt
the habit of sprinkling 'pure @safe nothrow @nogc' (or similar)
all over their code as a precautionary measure. It seems like
this is more or less what the Mir developers have done.
This is, ultimately, a usability problem with the
language--sometimes it's best practice to write out the
attributes by hand, other times it's a code smell, and if a
library author doesn't know which is which, their users will
suffer for it.
In the long run, I hope that we can address this by allowing the
compiler to infer attributes for more functions; in the short
run, the best we can do is try to fix the affected libraries.
More information about the Digitalmars-d
mailing list