7 ms·
Rust calls it shadowing and throws this example: fn main() { let x = 5; let x = x + 1; let x = x * 2; println!("The value of x is: {}", x); }
by cdevs 9y ago
Rust calls it shadowing and throws this example:
fn main() {
let x = 5;
let x = x + 1;
let x = x * 2;
println!("The value of x is: {}", x);
}
Sure this is a syntax example and you shouldn't be creating Immutable variable x and then adding +1 to it for no reason. If you did have a reason you should add it to the variable name so it's more likely developers say let xPlusOne = x + 1;
Or a kitchen example:
Let cream = getRefridgeratorItem(cream);
Let whippedCream = blend(cream);
So you reply no sane language makes you do this but why didn't the author show that? His goal was to make things more readable but lets be honest functional programmers would judge you all day for making a promise and then copying over that promise with something else. You may do it at work but the purist trolls hate reading it.