News for hackers. Stuff that matters.

MasonOfSpoons

Re:The Case Against OOP Is Wildly Overstated on Friday July 31, 2020 @05:46PM (#24014567)
It feels a bit like a rhetorical device to discuss OOP in any context other than the version of Java that's currently in widest usage.
Re:The Case Against OOP Is Wildly Overstated on Friday July 31, 2020 @02:52PM (#24012357)
Pure functional languages are capable of this, although they likely aren't modeling it as you envision. Pure record constructors let you do perform arbitrary mutation on the stack (e.g. calling other functions to build field values), but once the constructor is called the returned reference is immutable.

This is likely cleaner than sharing a reference which is sometimes mutable and sometimes not. Rust of course allows for both mutable and immutable borrows, and that's a very powerful tool but it'd be complex if all you needed was field initialization.

The consensus across languages that's emerged is that initialization shouldn't be a group effort, with references escaping in various stages of partial initialization. Be it RAII in C++ or functional record constructors, the common theme is that initialization should be a single operation that can succeed or fail as a whole.

Re:The Case Against OOP Is Wildly Overstated on Friday July 31, 2020 @02:02PM (#24011554)
It really isn't, as OOP languages don't traditionally provide robust mechanisms around immutability. And why would they? The core design of OOP is to wrap mutable state behind methods which control that mutation. OOP was in many ways a reaction to C; shared mutable structs are harmful, so let's invent privacy.

Most of the languages which are suggested to be superior alternatives to OOP in this thread have immutable data records and algebraic data types as core building blocks. These are very different than C-style structs, as they can provide stronger safety guarantees without a massive ream of boilerplate.

A class or method interface promises unfortunately little around essential topics like mutability, concurrency, or termination.