7 ms·
I can't help wondering why so many new languages provide two separate mechanisms to define mutable and immutable variables. I see a value in defaulting to immu
by teo_zero 1mo ago
I can't help wondering why so many new languages provide two separate mechanisms to define mutable and immutable variables.
I see a value in defaulting to immutable unless explicitly stated, like in Rust. But having to choose between two different 3-letter words, like let and var, what stops one from always using var?
Coming to Jaithon in particular, I also wonder what the scope of immutability is, when it allows the following:
let names:list[str]=[]
names.push("whatever")
If a function takes a list[str] as input, how do I signal that it does or does not modify the list? And if it does, will it only shuffle the elements (e.g. sort) or will it also change the strings themselves (e.g. uppercase all elements)?
Const-ness is a complex topic, with more cases than can be captured by two keywords at variable definition.
- AbhiramaVS 1mo agoI can speak for Jaithon but this is standard across most languages who have like immutable and mutable variables. There is def nothing stopping you from using var everywhere, but (let) lets the compiler like catch any mistakes you did not mean to do. In jaithon, let is whats known as shallow: it prevents (in ur example) names = ... but the refrenced list is still mutable. Currently jaithon doesnt have anything like a read-only parameter so just knowing list[str] doesnt tell u anything about if a function mutates the list.