3 ms·
>The whole point of objects is to encapsulate mutable state, together with methods for mutating that state. Citation needed. I use my objects to hold immutable
by tormeh 12y ago
>The whole point of objects is to encapsulate mutable state, together with methods for mutating that state.
Citation needed. I use my objects to hold immutable state with methods that does not mutate that state.
- kyllo 12y agoWhat do you gain from using objects in that way, as opposed to immutable structs and functions?
- tormeh 12y agoI program in Scala, so structs are not a thing (classes can extend/"inherit" AnyVal to be allocated on the stack, though, I think). Functions are nice, but from a pure syntax standpoint I often prefer methods because it limits the parantheses. It's especially neat when the methods take no arguments, like .toString. But yeah, otherwise there's no difference, really.