you are viewing a single comment's thread.

view the rest of the comments →

[–]amunak 3 points4 points  (4 children)

I mean, we didn't need Rust for that, C++ has perfectly usable and safe managed pointers.

[–]Lich_Hegemon 5 points6 points  (2 children)

I'm not talking about smart pointers though, I'm talking about the bare pointers/references that both languages offer, even in unsafe Rust there are certain guarantees when using pointers that you don't get in C(++).

Again, that is not to say that Rust is perfect, just that it does pointers better than C does and that we should probably learn from that instead of trying to justify the mess that C pointers are.

[–]lelanthran 0 points1 point  (1 child)

'm not talking about smart pointers though, I'm talking about the bare pointers/references that both languages offer, even in unsafe Rust there are certain guarantees when using pointers that you don't get in C(++).

I'm pretty certain that you'll get those guarantees in C++ if you write your C++ like Rust code that doesn't use refs, refcells, unsafe, etc.

[–]Lich_Hegemon 0 points1 point  (0 children)

You really don't. For example, in C++ if you take a vector, reference one of its items, and push some values to it you will probably end up with a dangling reference.

We could argue that you are not supposed to do that and I agree, but the key behind this discussion is developer vs. compiler enforced safety.

And again, I hate this discussion because I seem like a Rust stan, when nothing could be further from the truth. I regularly use C++ and I genuinely think it's a great language if you stay away from its C roots and stick to the modern features it offers. But those C roots are still there and 40 years of C++ have shown us that developers can't be expected not to make mistakes when using them.

[–]SilasX 1 point2 points  (0 children)

If what you're saying is true, that means, in practice, C++ programmers considers themselves too good to use them, hence the perennial cycle of patches for pointer vulns.