5 ms·
> I agree. Private class fields seem totally unnecessary when you can simply "hide" functions and variables in a local scope and not export/expose it. This is
by simplotek 3y ago
> I agree. Private class fields seem totally unnecessary when you can simply "hide" functions and variables in a local scope and not export/expose it.
This is not true. Private members are a part of a class interface, while local/internal function/variables are not. They both serve totally different purposes. If you're using private members as a substitution to local/internal members, you're doing it in ways that are fundamentally wrong.
- dimal 3y agoI’m confused by this comment. How are private members part of the class interface? They are internal, not exposed to the outside, so how can they be part of the interface, which by definition is what the class exposes to the outside?
- kfajdsl 3y agoAt least in lower level languages like C or C++, private members are part of the interface since they affect how much memory needs to be allocated for an object.
- otikik 3y agoWell C++ had private, public and “friend” attributes. Classes that were “friends” could see and use their privates. I know it sounds bad. Not my fault