6 ms·
They are very different languages. Rust was designed to be GC-free and memory safe. D, on the other hand, has GC and is memory unsafe by default.
by nenreme 9y ago
They are very different languages. Rust was designed to be GC-free and memory safe. D, on the other hand, has GC and is memory unsafe by default.
- pjmlp 9y agoD being @system by default has already been discussed as a design error, but making @safe be the default would be a breaking change. So it is up to the community if they want to accept such change. I should note that they still need some help cleaning the standard library and compiler corner cases in regard to @safe.
- wtetzner 9y agoCould there be a compiler flag to flip the default to @safe,so it doesn't have to be added to each file?
- pjmlp 9y agoIt could eventually be an option I guess, but it would require anyway to recompile all code. As always in such cases, to validate binary libraries, they need some kind of metadata to indicate they are safe libraries (aka they only use of @safe or @thrusted code). .NET does this with MSIL metadata, Modula-3 does it directly on the module definition section, for example.
- destructionator 9y agoWell, if you actually use the GC and array range checks (also enabled by default), it gives you memory safety in the vast majority of cases. Though, indeed, the language does let you break that by default, it isn't something you are likely to do accidentally. GC + range checks provide memory safety to most programs without the kind of extra work you need in Rust. This is a big reason why they are so common in industry.
- issaria 9y agoCall me wrong if I misunderstood, but isn't reference counting also kind of GC?
- floatboth 9y agoRust doesn't use reference counting (until you want to use it)
- jordigh 9y agoIsn't borrow-checking a sort of compile-time reference counting? Not what people usually think of when they say "reference counting", but I wonder if it's a good way to think of borrow-checking.
- steveklabnik 9y agoSome people make this analogy, but it has so many caveats, and is so far away from what people think about as RC, and has very serious and significant differences, that I don't think it's a useful analogy, personally. I even might go so far as to say "actively harmful." Not totally sure though.
- leshow 9y agoNot really, it doesn't count references in the same way. The borrow checker maintains a set of rules that are more expansive than reference counting. For instance the rule that you may only have one &mut at a time, and no other references as long as &mut is alive. It also has something like linear types with ownership rules, where owned values can be used only once.
- WalterBright 9y agoYes, RC is a form of GC.
- umanwizard 9y agoOne of the biggest differences in practice between reference counting and GC (or "other forms of GC" if you consider RC a type of GC) is that nodes involved in a cycle will never be freed.
- WalterBright 9y agoIf you add: @safe: at the top of your code, it'll be memory safe (excluding issues which we plug 'em when we find 'em). I wouldn't say that makes it fundamentally different from Rust. What is fundamentally different from Rust is the approach D uses to implement memory safety.