33 ms·
> Has the whole 2-library thing been fixed? If you're talking about the whole Tango/Phobos (2 std libs) thing, it's fixed and Phobos won. But now there are opt
by generichuman 4y ago
> Has the whole 2-library thing been fixed?
If you're talking about the whole Tango/Phobos (2 std libs) thing, it's fixed and Phobos won. But now there are optional function attributes such as @nogc (checks that the code doesn't trigger the GC), @safe (memory safety checks) and nothrow that's causing a bit of a problem.
For example, not all libraries are @nogc. So if you want to use some library in your @nogc code and the library is not marked as @nogc, you can't use that library. This is not as bad as the two standard libraries problem but it restricts the libraries you can use.
The attributes are optional like I said, you can just ignore them and write code that uses the GC (not @nogc), code that is not explicitly checked by compiler for memory safety (not @safe) and code that throws exceptions (not nothrow).
Of course this is sort of expected in multi-paradigm languages, like some people disable C++ exceptions. But in D's case it feels like the compiler and library developers' efforts are spread thin.
- mhh__ 4y agoThe main issue with the nogc and nothrow flags is people taking a feature designed for careful consideration, and using them for building from-scratch code with often no philosophy other than a vague and usually completely unfounded mental model where GC == slow. Write the code first then measure it.
- generichuman 4y agoAgreed and I actually don't really care about the GC speed. I mostly use arenas / object pools and you can do that with or without GC. Sort of undecided on the exceptions though. The Result / Option type in Rust is pretty nice to use (and !?*T in Zig, which is nicer if you ask me). It forces you to handle exceptions explicitly which is pretty nice and you can be sure there is no overhead introduced by the compiler for handling exception stuff. I'd probably wrap all the exception throwing functions in my D codebases with Result type if we had language level support for sum types and match syntax. I know we have it in the standard library, I want it in the language with nicer syntax. I also want the GC to be replaced with deterministic destruction using RC + ownership analysis and optimizations like Lobster does, but that's wishful thinking territory.
- mhh__ 4y agoEven if it's small, the Option/Result style exceptions always have overhead in at least a limiting case whereas the unwinding style exceptions are basically zero cost with a modern compiler - the debt is paid in the implementation being tricky.
- generichuman 4y ago> unwinding style exceptions are basically zero cost with a modern compiler - the debt is paid in the implementation being tricky. D doesn't return values when an exception is thrown as far as I know. How are exceptions' costs are paid by tricky implementation? I thought exceptions require allocation and run-time type info and therefore always introduce some cost (this goes for D and C++). I guess returning values and allocating error strings statically can help with that (or maybe allocate some exception buffer on program start -- but that's technically "overhead"). Am I wrong, or missing some important context related to exceptions?
- mhh__ 4y agoIf you don't throw there's no overhead, hence Exception-al cases only. The Optional style always has an overhead but the cost of actually throwing is much less. Lots of people do statically allocate their errors now. Implementing stack unwinding properly is not trivial.
- p0nce 4y agoAgreed. @nogc is useful if you have no a disabled or no-runtime, or in tight loops. Other than that, it's more fruitful to use pools, benchmark the GC, keep scannable heap small.
- giancarlostoro 4y agoIt's crazier even when you consider how insanely fast the official D Forums render. I'm going to go out on a limb but I kind of doubt Vibe.d is plastered with @nogc everywhere. I am looking forward to the borrow checker being added to D on the other hand, that ought to be a little more interesting.
- destructionator 4y agoThe official forums don't actually use vibe.d. vibe has the most marketing out of the D web frameworks, followed by hunt, but there's actually a few more too that just don't get as much attention, despite being older and possibly more widely used behind the scenes! The official forum uses the `ae` library. (And I have to mention my own `arsd` library which I'm pretty sure is the oldest web lib - mine dates back to 2008, but ae's pretty old too so he might beat me, and mine actually does better on some benchmarks despite me using GC and such with wild abandon.) That said though, yeah, I don't think any of them use `@nogc`. I've actually tried to get the gc to interrupt audio code before and couldn't even hear it. I'm sure a bigger heap to scan might cause a problem in some situations, but these fears are really overblown in the popular commentariat.
- lenkite 4y agoIs the phobos standard library gc free ie @nogc ? Stuff under std.range, std.container, etc ?
- generichuman 4y agoParts of it are `@nogc`, not all of it. You'd have to check the documentation for each function you want to use (or write `@nogc` code that uses the std and see if the compiler complains I guess).