DEV Community

loading...

Discussion on: How Rust Lets Us Monitor 30k API calls/min

Collapse
nemesiscodex profile image
Julio Daniel Reyes • Edited

With C/C++ is really easy to make a mistake with the memory allocations and shoot you in the foot.
With rust, your code won't compile if you have those problems and will even tell you what you're doing wrong and give you hints on how to solve it.
Also if you want to manage memory yourself, you can, but you will need to specifically say the code is unsafe, so if you make a mistake there, at least you will know where to look.

Collapse
gronkdaslayer profile image
gronkdaslayer

It's easy to make mistake if you're not careful, or don't know what you're doing.

Rust does help a lot but you can still do things like this:

fn main() {

let mut arr= [1,2,3];
for a in 0..10 {
arr[a] = arr[a] + 1;
}
}

Which will obviously panic. Essentially, stack overflows are still possible.
C/C++ puts the onus on the developer, which is not always a bad thing. If you ever get to write device drivers, you'll realize that you must remain extremely disciplined when writing your code, and it's not just a matter of language.

I actually like Rust. I'm seriously considering rewriting some code we have (in Java, which I dislike a lot) and use Rust to do so. It's mature enough, and it has a fair amount of crates that I can use and not worry about writing myself.

The problem with higher level languages, like Java, Node, Python, C# and Rust to a certain extent is that they make devs become lazy and complacent. They don't check return codes from functions, don't check for null pointers, and they let the GC take care of the memory for them. At least Rust doesn't have a GC, which is a very good thing.