Discussion about deprecating @nogc and workarounds

Dukc ajieskola at gmail.com
Mon Sep 9 16:00:47 UTC 2024


solidstate1991 kirjoitti 6.9.2024 klo 12.37:
> A lot of people are arguing (especially on Discord) that `@nogc` should 
> be discarded entirely in favor of betterC.
> 
> [snip]

Putting my thoughts without having looked at other replies first. No 
idea whether I'll go along with or against with what most have written.

Of these two, my gut reaction it's betterC that should (mostly) go. It 
is far better for the language to be pay-as-you-go. If not using 
non-shared static variables and not starting threads, the langauge 
shouldn't (attempt to) link in threading from the runtime. If not using 
exceptions, exception throwing/catching shouldn't be linked in. And so on.

For the most part, simply not using the D-specific functionality would 
be equal to betterC in this scheme. There are some exceptions to this 
rule. For example, assertions normally throw an error on failure instead 
of just aborting, and a header-only vanilla D library probably needs to 
provide module constructors and destructors even if they do nothing to 
avoid ABI changes if such logic is added in the future.

But even those can be solved with individual compiler switches. I think 
betterC should ideally be only be a shortcut for some set of compiler 
switches that that could all be enabled individually just as well, as 
opposed to a monolithic set of compiler and language changes.

As for `@nogc`, I do agree it's benefit-to-weight ratio feels 
questionable. If we didn't have it, I would be sceptical about adding it 
to the language. But since it has already been in the language for a 
long time, it needs stronger justification for removal than rejecting it 
anew would need, even with editions. Plus, people do occasionally find 
it useful. Therefore I'm a bit sceptical about but not strongly against 
removing it.


More information about the Digitalmars-d mailing list