July 15, 2022

On Friday, 15 July 2022 at 09:27:51 UTC, LinguisticMystic wrote:

>

I'm looking for a modestly mature language to be a C++ replacement for my hobby needs. D seems to be a good one as it ticks all the boxes of C++ while fixing most (all?) of its flaws. However, what confuses me is the fact that D has a garbage collector. My necessary requirement is that the runtime should not include any such thing. And D does have some sort of @nogc switch. My question is, how usable is the scenario of GC-free programs in reality? Does the switch apply globally, so that the compiled binary is free from GC code? How many essential libraries can work without GC? Is it better for me to look elsewhere if I don't want GC?

Thanks for your clarifications!

It is perfectly usable without a GC

You have access to malloc/free from libc and also allocators, so you can do what ever you want!

I am working on an online RPG targeting WASM without touching the GC at all, no RAII (thanks to scope guards aka defer, scope(exit)), no exceptions and it's been super smooth

  • game server

  • login server

  • master server

  • front end

  • database stuff

D is a very pragmatic language, i still use the GC for tooling projects and the deployment scripts where the GC doesn't have any impact at all, it was very useful to have even thought not necessary

https://www.kdom.xyz/

If you don't want the GC then you know what you are doing you don't want to deal with 3rd-party anyways since they can mess up your memory allocation strategy

You can consume C/C++ code with D, so you can consume their entire ecosystem with ease

I consume GLFW on desktop, Freetype for fonts, OpenGL/OpenAL for gpu/audio and PostgreSQL for the database, they are all C projects and the integration is super smooth

And there are lot of people around developing D libraries that are @nogc compatible

July 15, 2022

On Friday, 15 July 2022 at 11:48:31 UTC, Araq wrote:

>

On Friday, 15 July 2022 at 11:18:15 UTC, Ola Fosheim Grøstad wrote:

>

Anyway, you don't have to stick to one language. You can mix.

But you shouldn't mix as debugging and the tooling situation in general across languages is terrible. At least when "mixing" implies some sort of scripting language with its own interpreter loop.

That's false

I work with D and also some C libraries, and i can debug my program and step into C code without issues

Proof: (lib: mongoose, statically linked)

https://i.imgur.com/C2vjGOo.png

July 15, 2022

Little Rant:

Guys, when someone comes and ask if something is feasible without component X, you shouldn't tell them they are wrong for wanting to do it the way they want to do it

D is perfectly great for using without the GC, just like using C is perfectly great without a GC, just like Rust is perfectly great withotu a GC, they are equivalent

GC is only here as an optional scratch buffer, and it is very handy to have when you need it

We should welcome people with their usecase and make them feel safe for wanting to achieve what they want to achieve

If someone asks to not use the GC and you tell them "you shouldn't really", they'll go check the next language in their list of "interesting languages"

D a great language because it is pragmatic and polyvalent, it is a strength, as a community, let's be pragmatic too and accept that some folks doesn't want to use a GC!

It's like OOP, not everything needs it, not every meal needs salt, not every mattress needs to be white, not every cars needs to be grey

July 15, 2022
On Fri, Jul 15, 2022 at 02:55:45PM +0000, ryuukk_ via Digitalmars-d wrote: [...]
> You can consume C/C++ code with D, so you can consume their entire ecosystem with ease
> 
> I consume GLFW on desktop, Freetype for fonts, OpenGL/OpenAL for gpu/audio and PostgreSQL for the database, they are all C projects and the integration is super smooth

I can confirm this. In my own projects I use all sorts of C libraries with no problem: sqlite3, freetype, MPFR, Xlib, XCB, EGL, Vulkan, etc.. It's not even a problem that I freely use GC in my D code; that does not stop me from using C libraries easily.


T

-- 
Public parking: euphemism for paid parking. -- Flora
July 15, 2022

On Friday, 15 July 2022 at 15:05:24 UTC, ryuukk_ wrote:

>

On Friday, 15 July 2022 at 11:48:31 UTC, Araq wrote:

>

On Friday, 15 July 2022 at 11:18:15 UTC, Ola Fosheim Grøstad wrote:

>

Anyway, you don't have to stick to one language. You can mix.

But you shouldn't mix as debugging and the tooling situation in general across languages is terrible. At least when "mixing" implies some sort of scripting language with its own interpreter loop.

That's false

I work with D and also some C libraries, and i can debug my program and step into C code without issues

Proof: (lib: mongoose, statically linked)

https://i.imgur.com/C2vjGOo.png

I think he was referring to mixing a compiled language with Lua, or something like that.

July 15, 2022

On Friday, 15 July 2022 at 09:27:51 UTC, LinguisticMystic wrote:

>

I'm looking for a modestly mature language to be a C++ replacement for my hobby needs. D seems to be a good one as it ticks all the boxes of C++ while fixing most (all?) of its flaws. However, what confuses me is the fact that D has a garbage collector.

Learn like the GC doesn't exist. You won't even try hard to learn. Most things are things you already know and are familiar with. I think, you won't say also "what's up with that GC".

Welcome to the club, to the D family...😀
SDB@79

July 15, 2022

On Friday, 15 July 2022 at 14:55:45 UTC, ryuukk_ wrote:

>

D is a very pragmatic language, i still use the GC for tooling projects and the deployment scripts where the GC doesn't have any impact at all, it was very useful to have even thought not necessary

Same here, products are @nogc but to do them you need quite a lot of tools and one-time experiments, and those can be with GC usage.

July 16, 2022

On Friday, 15 July 2022 at 14:55:45 UTC, ryuukk_ wrote:

>

You can consume C/C++ code with D, so you can consume their entire ecosystem with ease

Not template heavy C++.

July 16, 2022

On Saturday, 16 July 2022 at 07:04:03 UTC, Ola Fosheim Grøstad wrote:

>

On Friday, 15 July 2022 at 14:55:45 UTC, ryuukk_ wrote:

>

You can consume C/C++ code with D, so you can consume their entire ecosystem with ease

Not template heavy C++.

Taking a chance to advertise, up to c++17 mostly not a problem, some tweaks by hand might be needed in generated code though.

https://github.com/Superbelko/ohmygentool

July 16, 2022

On Friday, 15 July 2022 at 09:27:51 UTC, LinguisticMystic wrote:

>

However, what confuses me is the fact that D has a garbage collector. My necessary requirement is that the runtime should not include any such thing. And D does have some sort of @nogc switch.

The @nogc is primarily that you aren't allocating or handling anything that uses (or may cause) the GC to run. You might need @nothrow as well.

Personally i love putting as much temporary allocations as i can on the stack, and leaving cleanup to instantly and cleanly be handled by the function cleanup code.

In C/D one of my favorite things would be to allocate everything as a single block and then assign pointers as necessary so a single free will handle it rather than say 20-30.

But if you aren't using the built-in array allocation, or an algorithm that will try to change the allocated memory then it should be fine. Not sure about the allocator template use, but doing structs and malloc/free should be a workable pair without relying on the GC at all.

But i'm very rusty on all this anymore :(