3 ms·
>when I see let, I can make assumptions about it not being mutated, which is a huge win in a large codebase. What we know is that this won't work: let p = P
by fauigerzigerk 9y ago
>when I see let, I can make assumptions about it not being mutated, which is a huge win in a large codebase.
What we know is that this won't work:
let p = Person("one")
p = Person("two")
But we don't know whether this will work:
p.name = "three"
It depends on whether Person is a struct or a class, but that information is not available locally. let/var is fine, but in terms of information content it is strictly worse than what const can do in C.
- AsyncAwait 9y agoYou're right, if reference types are involved, it becomes tricky, however to the extent that Swift encourages value types, it still provides value. > in terms of information content it is strictly worse than what const can do in C. True, however the Swift community largely adopted a "use let first, only use var if absolutely necessary" approach, which is strictly better in terms of mutability-related bugs than what it was in ObjC/C, as mutability there is used much more liberally than in Swift.