2 ms·
As fond as I am of Erlang, I still find it hard to picture an immutable OO language.
by macintux 9y ago
As fond as I am of Erlang, I still find it hard to picture an immutable OO language.
- mgummelt 9y agoWrite in scala using only "vals" and there you have it!
- lgas 9y agoNot quite because you can still have a val that points to a mutable object.
- kbp 9y ago> I still find it hard to picture an immutable OO language. Picture an object-oriented procedural language like Java, and then make everything immutable; for every 'void' method, return an updated copy of 'this'; for every non-void function, return a tuple of the updated copy and the value you were going to return. No change to const methods, obviously. And you're done, and you can still take advantage of encapsulation, polymorphism, and inheritance without any hoops. You can even do it in Java itself as a style thing without too much effort and only a modest amount of boilerplate. Alternatively, it's not that much work to build this same thing out of lambdas and dictionaries, if your language has those but not objects (adding mutation into that object system would then be trivial) (and of course, you can build dictionaries out of lambdas and lambdas out of objects, if need be).