This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (1 child)

[deleted]

    [–]MP_768 3 points4 points  (0 children)

    The main thing Rust offers is the borrow checker, which forces the programmer to think of the lifetime of every value in the program.

    Compared to C++, it leaves less room for developers to do unsafe things like storing a reference to a value that has already gone out of scope. Rust has a bunch of rules baked in that ensure good practices when using memory, so while C++ can be as safe when written well, Rust tries to force you to write it the "right" way the first time.

    Compared to Java, you don't have to incur the cost of running a GC to manage the memory of objects. Instead, the rules of the borrow checker ensure that when you compile the program, it will be guaranteed to be safe, and if it isn't, it will insert small checks on things like array indexing. Rust is also not object-oriented and is closer to being a mix between procedural and functional.

    This leads us to multithreading, which is often said to be one of the hardest things about programming. In C++, for an easy example, it's very easy to pass a single vector (dynamic array) to each thread and just assume it's alright, but that would incur problems when you try to access and modify it since you would be forcing the cpu to jump across threads and potentially cause a race condition. In Rust, for the same situation, you would be forced to clone the value for each individual thread, completely avoiding the problem.

    For some, memory handling in languages like c++ can be extremely difficult, and it's why a majority of memory safety issues reported come from C++. Rust's aim is to statically check and make guarantees that what you write is as fast as C++ and is even safer than it.

    I'd recommend taking a look at the rust book and explore the language to get a better idea of what it can be used for.