3 ms·
Yes, it's "let" in Swift and in some (semi)functional programming languages too. > in practice "var" are an order of magnitude more rare than "val" Or rather,
by mojuba 4y ago
Yes, it's "let" in Swift and in some (semi)functional programming languages too.
> in practice "var" are an order of magnitude more rare than "val"
Or rather, it should be that way. Agreed, and I think because the world has been moving more and more towards functional style over the past decades, I'd predict that the next big language that will make it to the mainstream will likely take the approach "immutability by default".
- V-2 4y agoOn Android - my platform - 99% of var usage is just for the sake of dependency injection, which is an inevitable concession because basic building blocks of an app (like Activities, Fragments) are instantiated by the SDK, not your code, so neither your code nor the libraries it relies on have control over it and thus the DI has to happen "on the fly", by mutating fields as soon as it becomes possible. It leaves a bit of a bad taste still, but it's very much a fixed convention and therefore kind of... compartmentalized, I guess. And harmless, because I don't expect Dagger 2 to suddenly misbehave and forget to set a field.
- V-2 4y agoI mean, in well-architected codebases of course. I've been lucky (or picky) enough to mostly work with such though.