Hi thanks for the detailed response. As I said I do understand the reasoning behind it and I have no problems with shadowing in different scopes, my problem, as mentioned in post, is with shadowing in the same scope. I see more cons than pro in that case. Yes its not exactly mutation in theoritcal sense but can achieve the same result of accidental mutation with this.
Shadowing is most useful when you are parsing keyboard input:
usestd::io;letmutnum=String::new()io::stdin().read_line(&mutnum).expect("Failed to read line");letnum:usize=num.trim().parse().expect("Failed to parse number");// Continue to use num as immutable usize. The mutable String is now not accessible any more.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi thanks for the detailed response. As I said I do understand the reasoning behind it and I have no problems with shadowing in different scopes, my problem, as mentioned in post, is with shadowing in the same scope. I see more cons than pro in that case. Yes its not exactly mutation in theoritcal sense but can achieve the same result of accidental mutation with this.
Shadowing is most useful when you are parsing keyboard input: