Jump to page: 1 2 3
Thread overview
Idiomatic D using GC as a library writer
Dec 04, 2022
vushu
Dec 04, 2022
Adam D Ruppe
Dec 04, 2022
vushu
Dec 04, 2022
Ali Çehreli
Dec 04, 2022
vushu
Dec 04, 2022
Sergey
Dec 04, 2022
Ali Çehreli
Dec 04, 2022
Adam D Ruppe
Dec 04, 2022
Adam D Ruppe
Dec 04, 2022
Ali Çehreli
Dec 04, 2022
rikki cattermole
Dec 04, 2022
Adam D Ruppe
Dec 04, 2022
Ali Çehreli
Dec 05, 2022
Patrick Schluter
Dec 05, 2022
jmh530
Dec 04, 2022
Siarhei Siamashka
Dec 04, 2022
Adam D Ruppe
Dec 05, 2022
Guillaume Piolat
Dec 05, 2022
vushu
Dec 04, 2022
Hipreme
Dec 04, 2022
vushu
Dec 04, 2022
bachmeier
Dec 04, 2022
ryuukk_
Dec 05, 2022
vushu
Dec 05, 2022
Guillaume Piolat
Dec 05, 2022
vushu
Dec 05, 2022
cc
Dec 06, 2022
vushu
December 04, 2022

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.

December 04, 2022
On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote:
> What are your thoughts about using GC as a library writer?

Do it. It is lots of gain for very little loss.

> If you wan't to include a library into your project aren't you more inclined to use a library which is gc free?

No, GC free means the library is necessarily more complicated to use and will likely result in a buggier program.

> Since to get most exposure as a D library writer you kinda need to make it gc free right?

All of the top 5 most popular libraries on code.dlang.org embrace the GC.
December 04, 2022

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.

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.

December 04, 2022

On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote:

>

Dear dlang community.

I am unsure about what idiomatic D is.

Idiomatic D code produces the correct result, it's readable, and it's easy for others to use.

>

Some of the Dconf talks tells people just to use the GC, until you can't afford
it.

"can't afford it" in what sense? Pauses for garbage collection are one thing, overall runtime performance is something completely different. Avoiding the GC won't magically make your program faster.

>

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?

Depends on the library, but most of the time it's best to use it. D's main problem at this point is a lack of high-quality, easy-to-use libraries - not libraries that use the GC.

>

If you wan't to include a library into your project aren't you more inclined to use a

library which is gc free?

The moment I have to think about memory management, I start looking for a different library. I suppose there's nothing wrong if a library avoids the GC internally (since that won't affect me). The GC has never caused problems for me. It has made my life easier.

December 04, 2022
On Sunday, 4 December 2022 at 12:37:08 UTC, Adam D Ruppe wrote:
> On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote:
>> What are your thoughts about using GC as a library writer?
>
> Do it. It is lots of gain for very little loss.
>
>> If you wan't to include a library into your project aren't you more inclined to use a library which is gc free?
>
> No, GC free means the library is necessarily more complicated to use and will likely result in a buggier program.
>
>> Since to get most exposure as a D library writer you kinda need to make it gc free right?
>
> All of the top 5 most popular libraries on code.dlang.org embrace the GC.

That's great to hear thanks! I was worried if my library should be GC free or not and how it will affect the adoption of it. Seems like there is no concern.


December 04, 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 :)

December 04, 2022
On Sunday, 4 December 2022 at 12:37:08 UTC, Adam D Ruppe wrote:
> All of the top 5 most popular libraries on code.dlang.org embrace the GC.

Interesting. It seems that most of the community suppose that “library” should be used from D :-)
But in my opinion - “foreign library experience” is much more important. The usage of D is not that wide… but if it will be possible to write library in D and use it from C/++/Python/R/JVM(JNI)/Erlang(NIF)/nameYourChoice smoothly it will be a win. Run fast (it could be Rust, Zig) extension/library from more high level/less safe/slower dynamic languages. And not only run but also write fast(here is D and Nim could be chosen).

Many languages do not have GC inside.. and others have their own. And if your library is going to manipulate objects from other languages with different memory management approach - it could be tricky to do that with GC. You need to make that both GC become friends
December 04, 2022
On 12/4/22 05:58, vushu wrote:

> I was worried if my library should be GC free

May I humbly recommend you question where that thinking comes from?

Ali

P.S. I used to be certain that the idea of GC was wrong and the creators of runtimes with GC were simpletons. In contrast, people like me, people who could understand C++, were enlightened. Then I learned.

December 04, 2022
On 12/4/22 06:27, Sergey wrote:

> if it will be possible to write
> library in D and use it from
> C/++/Python/R/JVM(JNI)/Erlang(NIF)/nameYourChoice smoothly it will be a
> win.

Years ago we tried to call D from Java. I realized that it was very tricky to introduce the calling thread to D's GC. D's GC needed to stop the world, which meant it would have to know what threads were running. You can never be sure whether your D library function is being called from a thread you've known or whether the Java runtime (or other user code) just decided to start another thread.

We failed and D was replaced with C++.

Ali

December 04, 2022
On Sunday, 4 December 2022 at 15:57:26 UTC, Ali Çehreli wrote:
> On 12/4/22 05:58, vushu wrote:
>
> > I was worried if my library should be GC free
>
> May I humbly recommend you question where that thinking comes from?
>
> Ali
>
> P.S. I used to be certain that the idea of GC was wrong and the creators of runtimes with GC were simpletons. In contrast, people like me, people who could understand C++, were enlightened. Then I learned.

I also come from C++ and as you know it, the community over there isn't quite fond of GC.
So I just logical think that by excluding the GC you actually widen the range of usage.

But if I only want to cater to the d ecosystem then using GC is the recommended way.


« First   ‹ Prev
1 2 3