3 ms·
Tell me you've only written in a memory managed language (Java, C#, Go) without telling me. For myself and many that I've interacted with, Rust's Borrow Checke
by John23832 4y ago
Tell me you've only written in a memory managed language (Java, C#, Go) without telling me.
For myself and many that I've interacted with, Rust's Borrow Checker and memory system saves me from the PTSD of segfaults and null pointers.
I'd love to see the idea of borrow checking and scoped based memory extended to other languages, but that's what makes Rust great for now.
- plasticeagle 4y agoWell, I don't know about borrow checkers, but scoped memory was added to C++ over a decade ago. In fact, I led the charge to remove every single new and delete from our codebase, and cause add it to the list of things disallowed by the static analysis tools. Today, I wouldn't use new or delete in any C++ program for any reason. Segfaults and null pointers have become extremely rare.
- John23832 4y agoThanks for the response. I appreciate that RAII is in C++ as well. RAII is an addition to C++. You can write valid C++ with memory leaks all over the place. This is the nature of being a superset of C. In Rust, there is no other way (outside of using unsafe). It is a language based around compile time memory safety. Segfaults and null pointers aren't extremely rare, they're extremely rare in modern C++ (which is a subset of all C++) The borrow checker validates references as they are passed throughout your program. You can have either (many immutable references || one mutable references). This may seem simple but is key to the memory safety ideas. The usages of references are validated. Move semantics are checked at compile time.
- rami3l 4y agoHowever the borrow checker is not only about new/delete, it also prevents other forms of reference invalidations (e.g. when holding a reference to a vector element while appending to the vector, that reference can become invalid when the vector gets resized).