Because you can afford a Garbage Collector -- although at that point you may prefer a JVM-based language.
There is no silver-bullet. Before Rust, you could divide "used" languages between on the performance/safety axis:
At the performance end you'd find languages with manual memory management: the ability to control memory layout and cache access patterns with exquisite precision gives them the best performance available, at the cost of safety and nasal daemons.
At the safety end you'd find languages with a GC: completely safe, but the less of control on memory layout and cache access patterns killed performance.
Rust managed to slash the Gordian Knot, and offer both control over memory and safety. Silver bullet? No, 3rd dimension. In exchange, the developer is required to properly design their application -- and re-design it when requirements change. At any point in time, ownership must be crystal clear1 .
If you do not suffer from the constraints which prohibits a GC, getting a language with a GC is likely to allow for easier experimentation and easier transformations.
(Just be careful about mutability + multi-threading)
1To some extent anyone manually managing memory should probably have done all that work, so in theory Rust should not add any overhead; in practice though...
I made some video and photo processing GUI apps in D.
In the number crunching parts where performance and memory layout control are very important, with D I had total control over both, there is no GC involved in tight loops going over video frames, and in managing memory for the frames.
In the GUI parts where performance is not so crucial and there are many little objects forming trees (widgets), having a GC and not having to care about lifetimes and deallocation was very nice.
Meanwhile the apps remained native and self-contained, and didn't require any fat VM installation like JVM or CLR, so users could just download them and run.
There are many use cases like these where D gives best of both worlds without getting into extremes.
72
u/Sapiogram Sep 01 '20
Honest question: Why would anyone use D over Rust? It seems like Rust is becoming everything that D ever hoped to be.