4 ms·
The problem is `fop` should be `foo`: foo = 5 fop = 6 Keywords like `let` solve this problem: let foo = 5 fop = 6 # error
by ReleaseCandidat 5y ago
The problem is `fop` should be `foo`:
foo = 5
fop = 6
Keywords like `let` solve this problem:
let foo = 5
fop = 6 # error
- ErikCorry 5y agoOr := for declaration like Go and Toit
- ReleaseCandidat 5y agoYes, or another symbol instead of `=` for assignment, like `<-` (F#)
- deathanatos 5y agoNot entirely: let foo = a(); let foo = b(foo); let fop = c(foo); let foo = d(foo); (Which is valid, e.g., in Rust.)
- TheEzEzz 5y agoYou do get a warning, though. And most Rust projects I've seen usually adhere to 0 warnings.
- renox 5y agoI hate variables shadowing, I'm very surprised that they allowed it in Rust, I saw an unpected behaviour caused by variable shadowing in C++ (global variable hidden by member variable) just last week..
- Too 5y agoA good IDE has many other safety nets for that error. Auto completion, highlight matching variable, gray out unread variables and warning of unused assignment. I’ve written lots of python and can’t recall ever having this issue. More likely is a logic typo of two similar variables like length_x vs length_y, where a “let” wouldn’t have saved you anyway if both are already defined. JavaScript, pre strict TS, on the other hand, where missing var implied global was a real motherload of bugs. Or kotlins “val” vs “var” changing semantics completely…wow. But those are different concepts from basic definition I know.