class MyStuff {
int myState;
void myFunc() {
...
}
}
This is somehow "encapsulated". But start calling myFunc() at different times from different threads and see if myState behaves more like a stack variable or a global variable.
OO made it much more socially acceptable to pollute your code with this kind of "encapsulation". And OO devs decided that even this was too much of a straightjacket - some people liked C#'s take on properties, where you didn't have to work so hard writing getters and setters (further breaking encapsulation).
Once you take away inheritance ("prefer composition"), polymorphism (better offerings elsewhere), encapsulation (not encapsulation!), message-passing (better offerings elsewhere), you're left with a small syntactic trick that really wasn't that hard to do in C.
Even Lua gives you that [1]:
> This use of a self parameter is a central point in any object-oriented language. Most OO languages have this mechanism partly hidden from the programmer, so that she does not have to declare this parameter (although she still can use the name self or this inside a method). Lua can also hide this parameter, using the colon operator.
function Account.withdraw (self, v)
self.balance = self.balance - v
end
function Account:withdraw (v)
self.balance = self.balance - v
end
Not at all!
This is the main reason OO has dominated for so long. OO has somehow taken on the meaning "Anything which isn't C".
And it's not even an accurate representation of C, it's a straw man version of C. C programmers know the perils of global variables.
Here is some code:
If I take the above code and make it look like C: Yuck! Global variable! disgusting!Now I make it look like Java:
This is somehow "encapsulated". But start calling myFunc() at different times from different threads and see if myState behaves more like a stack variable or a global variable.OO made it much more socially acceptable to pollute your code with this kind of "encapsulation". And OO devs decided that even this was too much of a straightjacket - some people liked C#'s take on properties, where you didn't have to work so hard writing getters and setters (further breaking encapsulation).
Real C Programmers™ actually encapsulate: