3 ms·
You tend to not put temporary results of loops in instance variables, but in local variables. Which aren't visible externally at all. And yes, if you do have t
by mpweiher 4y ago
You tend to not put temporary results of loops in instance variables, but in local variables. Which aren't visible externally at all.
And yes, if you do have that exceptional case of a complex algorithm that needs to store partial results in ivars as they are required by different methods and inconvenient to pass around individually, those ivars tend to not be exposed.
In fact, you'd more likely create a separate context object that you pass around, so also not visible externally.
- mrkeen 4y ago> You tend to not put temporary results of loops in instance variables, but in local variables. Which aren't visible externally at all. Cool! Then it follows: If a result is not temporary, then it can be immutable. Properly immutable, not just final. If a result is temporary, then it is not to be visibly external at all. Not as a field, and not via any getter. I could live with that.
- mpweiher 4y agoThat doesn't follow. Objects do (much) more than implement algorithms in loops. In fact, I'd say that if you're doing algorithms as objects, you're almost certainly Holding it Wrong™. Algorithms tend to be perfectly fine contained in a method of an object.