DEV Community

Discussion on: My first impressions of Rust

Collapse
 
jeikabu profile image
jeikabu

It comes down to personal preference, but I like the variable shadowing. When working with immutable types and stricter type system you tend to end up with a lot of temporary locals:

let s = String::new(something);
let stripped = a.trim();
let s_cstr = CString::new(stripped);
let bytes = s_cstr.as_bytes_with_nul();

As in this case, you can often try to do more on one line, etc. But it’s handy to avoid creating a block expression.

Another thing I like about Rust is how it moves by default. This is similar to move semantics in c++11.

Collapse
 
deepu105 profile image
Deepu K Sasidharan

Agreed it is useful but to me it can be abused and can cause accidental errors as well. Maybe once you are experienced enough it might not be a problem, but then the same argument can be used for languages like JavaScript that lets you mutate by default. I can say that I have not had that issue as I'm experienced and I do not do it.