In uno dei tanti rilanci anti-OOP su cat-v.org ho trovato un passaggio di Joe Armstrong ha sollevato diverse obiezioni contro il modello OOP, una delle quali era la seguente:
Objection 4 – Objects have private state
State is the root of all evil. In particular functions with side effects should be avoided.
While state in programming languages is undesirable, in the real world state abounds. I am highly interested in the state of my bank account, and when I deposit or withdraw money from my bank I expect the state of my bank account to be correctly updated.
Given that state exists in the real world what facilities should programming language provide for dealing with state?
OOPLs say “hide the state from the programmer”. The states is hidden and visible only through access functions. Conventional programming languages (C, Pascal) say that the visibility of state variables is controlled by the scope rules of the language. Pure declarative languages say that there is no state. The global state of the system is carried into all functions and comes out from all functions. Mechanisms like monads (for FPLs) and DCGs (logic languages) are used to hide state from the programmer so they can program “as if state didn’t matter” but have full access to the state of the system should this be necessary.
The “hide the state from the programmer” option chosen by OOPLs is the worse possible choice. Instead of revealing the state and trying to find ways to minimise the nuisance of state, they hide it away.
Che cosa si intende esattamente con questo? Ho pochissima esperienza procedurale o di basso livello, in gran parte OOP, quindi probabilmente questo spiega quanto non mi sia familiare. E da un punto di vista più moderno, ora che è passata la maggior parte dell'isteria orientata agli oggetti (almeno per quanto posso dire), quanto pensate che quel passaggio sia preciso / pertinente?
Grazie per il tuo aiuto.