4 ms·
I forget who said it, but there's a quote along the lines of, "There's no problem in programming that can't be solved by adding another layer of indirection. Ge
by curun1r 9y ago
I forget who said it, but there's a quote along the lines of, "There's no problem in programming that can't be solved by adding another layer of indirection. Getters are just that, a layer of indirection. So they give you a hook to intercept a call and do something that wouldn't be possible with direct field access. Perhaps you want to lazy-load the field, or dynamically compute its value under certain circumstances. Whatever it is, if you use getters from the outset, you won't have to change code that calls the getters when you decide you need that indirection.
- saghm 9y agoFair enough, although those types of things seem like they'd need to be explicitly written, not auto-generated by a compiler (like the ones described as existing for Scala)
- simon_o 9y agoThat's the whole point of what Scala is doing. Allow flexibility to support such requirements later on, without forcing people to break source and binary compatibility, unlike in Java, C# etc. That's the reason why you can e. g. implement or override a def with a val.