The D standard library is built on GC, is that a negative or positive?

Steven Schveighoffer schveiguy at gmail.com
Wed Dec 14 01:47:29 UTC 2022


On 12/13/22 8:18 PM, H. S. Teoh wrote:
> On Tue, Dec 13, 2022 at 07:11:34AM +0000, thebluepandabear via Digitalmars-d wrote:
>> Hello,
>>
>> I was speaking to one of my friends on D language and he spoke about
>> how he doesn't like D language due to the fact that its standard
>> library is built on top of GC (garbage collection).
>>
>> He said that if he doesn't want to implement GC he misses out on the
>> standard library, which for him is a big disadvantage.
>>
>> Does this claim have merit? I am not far enough into learning D, so I
>> haven't touched GC stuff yet, but I am curious what the D community
>> has to say about this issue.
> 
> 1) No, this claim has no merit.  However, I sympathize with the reaction
> because that's the reaction I myself had when I first found D online. I
> came from a strong C/C++ background, got fed up with C++ and was looking
> for a new language closer to my ideals of what a programming language
> should be.  Stumbled across D, which caught my interest.  Then I saw the
> word "GC" and my knee-jerk reaction was, "what a pity, the rest of the
> language looks so promising, but GC? No thanks."  It took me a while to
> realize the flaw in my reasoning.  Today, I wholeheartedly embrace the
> GC.

So while I, too, don't hate the GC and embrace it, the truth really is 
that way way too much is dependent on the GC.

as I alluded to in my previous post:

```d
void main() @nogc
{
    import std.conv;
    auto v = "42".to!int;
}
```

fails to compile. Why? Surely, it can't use the GC for converting a 
string to an integer? Well, it doesn't. But if the string you give it 
happens to not contain a string representation of an integer, it wants 
to throw an exception. And the act of allocating and throwing that 
exception needs the GC.

We really really need to fix it. It completely cuts the legs out of the 
answer "if you don't want the gc, use @nogc". If we do fix it, all these 
questions pretty much just go away. It goes from something like 20% of 
phobos being nogc-compatible to 80%.

-Steve


More information about the Digitalmars-d mailing list