News for hackers. Stuff that matters.
Re:Adding Modules to C in 10 Lines of Code [pdf] by speps on Monday June 27, 2022 @06:24AM (#31892619)
D's standard lib is also a lot more mature than Zig's, obviously because of its age. I'd recommend D above Zig unless you want to contribute bug fixes to Zig.
Re:Adding Modules to C in 10 Lines of Code [pdf] by cyber_kinetist on Monday June 27, 2022 @06:39AM (#31892694)
But isn’t most of the D standard library unusable with BetterC mode (without GC)?
Re:Adding Modules to C in 10 Lines of Code [pdf] by Shadonototra on Monday June 27, 2022 @06:49AM (#31892768)
BetterC is not no GC mode, BetterC was made to make sharing D code easier with C

GC only exist if you call ``new MyThing``

Just use your allocators with malloc/free, that is what i do (you do the same in zig, allocators)

if you want to enforce no GC use in your APIs, there is the @nogc attribute you can use

Re:Adding Modules to C in 10 Lines of Code [pdf] by OskarS on Monday June 27, 2022 @07:50AM (#31893224)
> Just use your allocators with malloc/free, that is what i do (you do the same in zig, allocators)

If you do that, is it RAII like C++/Rust? Objects get destructed at end of scope, and members get destructed recursively? Or do you have to manually call `free()` on everything? (which, granted, is significantly easier in languages with `defer` mechanisms)

Re:Adding Modules to C in 10 Lines of Code [pdf] by Shadonototra on Monday June 27, 2022 @04:38PM (#31900471)
D has defer

    scope(exit):
    scope(failure):
    scope(success):
https://tour.dlang.org/tour/en/gems/scope-guards

You can do RAII with D too, it's your choice, based on your use case

Re:Adding Modules to C in 10 Lines of Code [pdf] by WalterBright on Monday June 27, 2022 @02:20PM (#31898509)
Yes, it is RAII and RAII is fully implemented in D.
Re:Adding Modules to C in 10 Lines of Code [pdf] by alphaglosined on Monday June 27, 2022 @03:26PM (#31899535)
But only for structs.

We really need to get actual reference counting into the language to cover classes properly as well.

It has been on my todo list to write a DIP for this for a while now. ~rikki.

Re:Adding Modules to C in 10 Lines of Code [pdf] by ntrel on Tuesday June 28, 2022 @09:17AM (#31907290)
Class instances can go on the stack too using `scope`:

  scope obj = new Object;
  ...
  // destroyed at end of scope
Re:Adding Modules to C in 10 Lines of Code [pdf] by nicwilson on Monday June 27, 2022 @08:14AM (#31893442)
RAII, though there is also `scope(exit)`
Re:Adding Modules to C in 10 Lines of Code [pdf] by mhh__ on Monday June 27, 2022 @03:07PM (#31899259)
BetterC is a hack designed to make it easier to migrate C code to D. It turns off everything that requires a runtime not just the GC