named arguments, string interpolation, please stop.

Adam Wilson flyboynw at gmail.com
Fri Jan 12 00:24:52 UTC 2024


On Thursday, 11 January 2024 at 23:09:46 UTC, Jonathan M Davis 
wrote:
> @nogc doesn't even prevent collections running while a function 
> is called. It just prevents that specific function from 
> triggering the collection (thanks to no allocations triggering 
> it). Another thread could trigger a collection while that 
> function is running. So, yes, in a single-threaded program, 
> it's equivalent to calling GC.disable, but in the general case, 
> it isn't.
>
> So, anyone actually relying on @nogc preventing collections is 
> arguably asking for trouble even with the current GC - though 
> it seems like the kind of folks who like to use @nogc are often 
> the kind of folks who are likely to avoid the GC entirely, so 
> if @nogc is used everywhere in their code, then they won't end 
> up with either GC allocations or collections. However, anyone 
> using it selectively really can't rely on it to avoid 
> collections unless their program is single-threaded and will 
> always remain so.
>
> - Jonathan M Davis

Indeed. I think that highly experienced D devs understand these 
subtle distinctions. But to the average dev it looks like an easy 
out. And IMO, this is the source of much of the angst over @nogc. 
The name implies that the GC is disabled during execution, and in 
single threaded programs it effectively is, but step outside of 
that box and the GC pause magically reappears despite @nogc being 
applied. So it *appears* to the average person that the language 
isn't doing as instructed. What people expect @nogc to do versus 
what it's specified to do are different things. But because 
people typically presume that their assumptions are correct they 
launch rants on the NGs before they bother to read the spec.

To some extent Rikki is right that @nogc might be better as a 
linter, because what it actually does is more in line with what a 
linter is expected to do. @nogc is a hygiene feature that can 
easily be misunderstood as doing something more than that.


More information about the Digitalmars-d mailing list