Doesn't GC, @nogc, safe, nothrown, * get in the way of getting things done?
Dukc
ajieskola at gmail.com
Fri Jun 12 03:32:57 UTC 2020
On Thursday, 11 June 2020 at 11:28:07 UTC, aberba wrote:
> What becomes the ideal trade-off??
In my opinion, in principle almost everything should be `@safe`
and `pure`. With `@safe`, it's mainly the interfaces to other
languages and some low-level memory handling or typecasting that
needs to be `@system`. This applies even to system programming:
If you look at the source of Powernex, surprisingly large parts
of it are `@safe` even when it's obviously very low level stuff.
With `pure`, IO is the main thing that can't be pure, pretty much
everything else should be. You usually should not need global
variables, so you should not need impurity either.
In practice, though, the annotations tend to be leaved off
because some library function being called does not use the
attributes. In case of `@safe`, one can work around this with
`@trusted`, but doing `pure` interface to such a library might
require too dirty hacks to be worth it.
With `nothrow` and `@nogc` it's more situation and taste
dependant. A general rule of thumb is that the lower level the
code, the more likely you want to use them. Also the return of
investment with these attributes isn't as high as with the first
two. They might not be worth the effort for a typical application
if they require any significant rethinking, even if the function
should in principle have the attributes.
More information about the Digitalmars-d
mailing list