by obua · 4y ago · 0 comments
foo = 5
fop = 6
Keywords like `let` solve this problem: let foo = 5
fop = 6 # error let foo = a();
let foo = b(foo);
let fop = c(foo);
let foo = d(foo);
(Which is valid, e.g., in Rust.)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.