3 ms·
how safe is D, compared to C/C++ on one end and Rust on the other end?
by fnord77 7y ago
how safe is D, compared to C/C++ on one end and Rust on the other end?
- vips7L 7y agoI would say it depends. Maybe Walter will chime in, but from what I can tell it is fully possible to use raw pointers (-betterC) and step into unsafe space, but if you're using the full runtime it should be as safe as go, java, etc.
- mhh__ 7y ago-betterC removes the druntime features, but pointer safety is gained with the -dip1000 flag (with @safe) regardless of whether you use betterC or not. @safe will also stop you doing obviously unsafe pointer arithmetic unless you abstract it into a @trusted function.
- MrRadar 7y agoIf you use the GC (and don't go out of your way to hide pointers/references from it) it's as memory-safe as any GC'ed language. If you avoid the GC and do your memory management manually you at least have RAII so it shouldn't be any less safe than C++. D also includes some (experimental?) language features which aim to improve memory safety[1] but they're nowhere near as robust as Rust's type system. [1] https://dlang.org/spec/memory-safe-d.html https://dlang.org/spec/memory-safe-d.html
- nicwilson 7y agoType safety: excellent, if you use @safe you have to tell the compiler you're doing nasty things with it. `cast` is a keyword so you can easily see where it is being done. Memory: very good with @safe (I've not use rust so I can't compare), there are a few holes in the corners. @safe is not the default though, although it is transitive so if main is safe then everything else has to be @safe or @trusted. Thread: not so much, we're working on it. You can do thread safe designs but it is ultimately on the programer to not stuff up.
- p0nce 7y agoOpt-in memory safety with annotating @safe. You pay for it if you want it.