2 ms·
> The thing is, code complexity can be managed superbly without the concept of a class. It can be managed by modules/namespaces, but without even that (a la C)
by kaba0 5y ago
> The thing is, code complexity can be managed superbly without the concept of a class.
It can be managed by modules/namespaces, but without even that (a la C), I really don’t see it managing complexity well. The important point of OOP is the visibility modifiers, not “methods on structs”, that would provide no added value whatsoever.
What OOP allows is - as mentioned - not having to worry about the underlying details at call site. Eg, you have a class with some strict invariant that must be upheld. In case of structs you have to be careful not to manually change anything/only do it through the appropriate function. And the bad thing is that you can make sure that your modification is correct as per the implementation, but what classes allow for is that this enforced invariant will remain so even when the class is modified - while now your call site usage may not fulfill the needed constraints.
- usrbinbash 5y ago> The important point of OOP is the visibility modifiers, OOP is not required for implementation hiding. It can be done entirely by convention (eg. names starting with an underscore are internal and not to be used). Go took this a step further and simply enforces a convention at compile time: Any symbol in a package not starting with an uppercase letter, is internal and cannot be accessed by the consumer.
- kaba0 5y agoWell yeah, and typing doesn’t need enforcement by compilers, we just have to manually check their usages. Maybe we should go back to Hungarian notation! I mean, snark aside, I really don’t think that variable/field names should be overloaded with this functionality. But I have to agree that this functionality is indeed not much more than your mentioned convention.