Re:Ask HN: What's the most simple thing you struggle to unde...
by zumu on Friday June 09, 2017 @02:32PM
(#14523381)
Thanks for taking the time to give these detailed responses.
One more question (restated from below):
Coming from FP where immutability is sacrosanct, I often wind up writing classes that are largely immutable, which doesn't seem like correct OOP. Is there a proper way to marry immutable data structures with OO?
Re:Ask HN: What's the most simple thing you struggle to unde...
by jtolmar on Friday June 09, 2017 @09:47PM
(#14525763)
The object-oriented world has been moving towards more immutable and mostly-immutable classes. This is sometimes awkward with large classes, so people use the builder pattern to get around it. (It's a case of languages having not caught up with practices.)
OO is mostly that plus the ability to forbid people from using the record without using the functions.
> by attaching the functions you create new copies of each function with a bound reference to the instance of data structure.
Yes, but the compiler won't actually copy the function, it'll implement it as something closer to the record plus modules approach (for example a record plus a pointer to the module). This might not be true if you're trying to use OO in a functional language.