Idiomatic D using GC as a library writer
vushu
danvu.hustle at gmail.com
Sun Dec 4 14:11:41 UTC 2022
On Sunday, 4 December 2022 at 13:03:07 UTC, Hipreme wrote:
> On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote:
>> Dear dlang community.
>>
>>
>> I am unsure about what idiomatic D is.
>>
>> Some of the Dconf talks tells people just to use the GC, until
>> you can't afford
>> it.
>>
>> If there are documents that describes what idiomatic D is then
>> I would appreciate it.
>>
>>
>> So my questions are:
>>
>>
>> What are your thoughts about using GC as a library writer?
>>
>>
>> If you wan't to include a library into your project aren't you
>> more inclined to use a
>>
>> library which is gc free?
>>
>>
>>
>> If that is true, then idiomatic D doesn't apply for library
>> writers.
>>
>> Since to get most exposure as a D library writer you kinda
>> need to make it gc free right?
>>
>>
>>
>> Cheers.
>
>
> "Until you can't afford", is something really extreme. There is
> a bunch of ways to deal with GC memory, what I would say that
> can't afford is when you're constantly allocating memory and
> because of that, making the program more prone to execute a
> collection. I haven't had any problem with the GC yet. If you
> think your program is slow, pass it on a profiler and you'll
> know the real problem. Don't think too much about that or else
> you're gonna lose a heck lot of productivity and end up
> creating needlessly unsafe code.
>
True that makes sense, I also tried using nogc in code, but it
complicates things.
The code is much easier to write when I don't work against the GC.
> If you're still gonna be hard headed against the GC, at least
> use slices when allocating from malloc, makes your code safe,
> readable and less variables to think about. Don't use raw
> pointers unnecessarily, and right now, the only reason pointers
> have been used in my code base was not for allocated memory,
> but for being able to modify a variable from another place when
> you need to store a variable reference. If you're only gonna
> modify it inside the function, use `ref` instead.
Thanks for the tips :)
More information about the Digitalmars-d-learn
mailing list