In Rust, and other languages actually as well, I made use of a lot of variables. This because it made the code a bit more self-documenting. But since

Did Rust teach me to use a lot of variables instead of inline expressions?

submited by
Style Pass
2024-10-09 11:30:05

In Rust, and other languages actually as well, I made use of a lot of variables. This because it made the code a bit more self-documenting.

But since I'm getting code reviews now I got the feedback that I should use as less variables as possible, and write code as inline as much as possible if the variable is not used in multiple places.

I also have the feeling that Rust kind of teached me to use a lot of variables because of the ownership and borrow system. Does someone else have an opinion on this?

You shouldn't be bothered by it, it's normal to have this kind of problems when working with multiple programming languages; me and my colleagues sometimes show this "lag" when switching languages such as using the match statement in the wrong order when switching between Scala and Rust (it works both ways), and using the let keyword in JavaScript when const was the right choice.

On the contrary I feel like Rust pushed me more towards an expression style "variableless" idiom, making functions only one expression, or only combining expressions. But I was already on that functional journey before coming to Rust, having done a bit of ocaml etc.

Leave a Comment