Object-oriented design is the roman numerals of computing.
Rob Pike
Joe Armstrong said in his thesis that Java is not even suitable for programming.
It is good idea to try to realize why.
The fundamental flaw, which cannot be eliminated, comes from the fact that the “designers” of Java lacked a required mathematical background.
The idea of mimicking the “real world” in which “objects having its internal state” is exactly what is wrong.
Yes, “object” of real world do have internal state, but this fact does not imply that the language for describing the world should have objects with a state.
Mathematics does not have any state for a reason and it is a meta-language for describing aspects of real world.
The way do deal with the state has been discovered long before OOP and the principle is that we just read and write the data as it is.
Every classic language since Common Lisp and Standard ML have the REPL functionality. The principle is that one can print a value of any type and then read it back into a system.
This is the way to deal with a state. This, unsurprisingly, is similar to what Erlang and telecom people called “in-wire” representation. We just spell it out.
Having “an encapsulated mutable state within an object” which is the main selling point of OOP is just wrong in a multi-threaded environment with an unrestricted write access.
The right way is to have an immutable binding or an immutable reference (as a proper, non-leaking abstraction – as an ADT).
Having at most one “mutable reference” is implicit in the classic FP languages due to immutability of a binding - one has to explicitly pass the value (of the type “ref”) along.
What Rust guarantees at the static type-system level (a major innovation) is implicit in the classic FP languages due to following mathematics instead of a processor (the principles on which it has been built).
Everything else just follows. Again, it is not about the identity of an object, but about having at most one (mutable) reference to every value.
This mimics the real world better, and, corresponds to a mathematical notion of an (at most one) arrow pointing to a value and thus selecting it. I think they call it a probe or something like that.
So, what Rust designers “discovered” or come up with is a fundamental notion which has been captured more than once by different branches of human knowledge.
In logic this notion is also implicit - every “fact” in \(\Gamma\) has only one implicit “arrow pointing at it”.
This is not the end of the story, however. It is seems that the only way to do computation reliably is by using symbolic manipulation (exactly as in mathematics and logic, using pen and paper) within a specialized (for immutability of bindings and lexical closures) G-Machine/.
In short, it has to be the Lambda Calculus (yes, all over again), not a
CPU-memory model with mutable state and concurrent arbitrary writes
(even C
was ok as long as there were no concurrency).
It is time to admit that a CPU-Memory model is just wrong (and we have to backtrack from this dead end) and is an ultimate technical dept.
Yes, yes, Windows, OpenJDK and Chromium works, but only until they don’t.
The early FP guys, like Joe Armstrong, did all the proper research.