News for hackers. Stuff that matters.
Re:Fish (shell) porting to Rust from C++ by John23832 on Tuesday January 31, 2023 @01:52AM (#34592078)
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.

Re:Fish (shell) porting to Rust from C++ by plasticeagle on Tuesday January 31, 2023 @03:45AM (#34592810)
Well, 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.

Re:Fish (shell) porting to Rust from C++ by John23832 on Tuesday January 31, 2023 @04:30AM (#34593129)
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.

Re:Fish (shell) porting to Rust from C++ by rami3l on Tuesday January 31, 2023 @08:14AM (#34594624)
However 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).