When i'm wrtiting code I visualize whats happening and how its working and interacting, not sure if anyone else does that |
No doubt, it's common. I see machines, sometimes electronic, sometimes mechanical, sometimes a mixture. Sometimes I see analogies (dealing a deck of cards for the operation of a stack, for example). I also will never forget the old Borland IDE's view of the CPU registers and the stack from back on the DOS days.
...theres just something about C++ that resonates with me... |
It may be more than that. Most of the languages you list don't support RAII (or at least not as directly), and they took a lot from C++, but left so much behind.
Whenever I work in C# or Java, I feel like my office has been stuffed into a phone booth.
So I should just make those variables public instead of private?
|
I didn't mean to convey that. I was trying to convey that the return of a reference to a member may as well remove privacy, but that's not a suggestion to make them public.
There are times when such values should be public, like a simple C struct. You'll know because there's nothing to protect about them, and nothing beats a simple usage like p.x, p.y, etc.
...on one hand, I need access to them... |
When member data represents what is genuinely internal, the need to access that data from outside a member function hints either a member function should be created to do that work, or something else in the design may be incorrect that brings that situation about.
Sometimes a class should be interior to a class, a private class. Such a class could be all public, but since it is otherwise private to the owning class, no one else can use it or get to it.
Sometimes classes should be friends to each other, but not frequently. When objects naturally work together as a family of components, perhaps making them friends (usually in one direction, very seldom both directions) makes sense.
The most important thing in such cases is that it shouldn't be a user feature.
because the entire point of the class (other than organizing similar methods and variables) is to hide and encapsulate data |
While encapsulation is generally the case, sometimes they're just structs.
The real points about classes may yet to be well documented. For example, if the point is to encapsulate, then what is the point of encapsulation? The answer may seem obvious, but sometimes things just need to be quite open. For example
1 2 3 4
|
struct cmp
{
bool operator()( int a, int b) {.....}
};
|
This is an older paradigm. We use lambdas for this now, but for a long while this was the primary way to make a comparison function (and it could be a template class). This is a class (just spelled struct). There is nothing to encapsulate, but the technique makes the instance usable like a function.
Sometimes the point of a class is to create a type more than anything else. One of the main features of the language (and many like it) is the ability to select a method by type. There may not be as much to encapsulate about it (like cmp above), but the type is informative on its own, when the occasion arises.
Sorry, I haven't studied your code just yet...and I need to change gears (I've been working on my car, blew a timing belt). I might check on it again later.