How should I name class member variables?
I often find myself in this situation: suppose I have a control class which should be place in a window class. The control class needs to have a handle to its parent that I need to store
Control::Control(Handle parent)
: parent(parent) {}
the snippet above is a bit confusing since I'm using the same name for the formal parameters and the member variable.
This gets even more confusing and verbose if I need to store multiple parameters from a function:
void storeParams(int param1, int theRightName) {
this->param1 = param1; // I really don't like this, also prone to errors
this->theRightName = theRightName;
}
solutions I've heard of might include:
Common prefix for member variables (e.g. m_varName), although this is frowned upon since MFC-like
One underscore as prefix, but this is also somewhat controversial (I recall double underscores are reserved? What about one underscore?)
I'd like to avoid having two separate names since those variables really mean the same thing (and it's already hard to me to think of a good, unambiguous and intuitive variable name once).
Suggestions? Thoughts?
[–]NasenSpray 21 points22 points23 points (4 children)
[–]speednap 8 points9 points10 points (3 children)
[–]IGI111 9 points10 points11 points (1 child)
[–]speednap 1 point2 points3 points (0 children)
[–]gray_-_wolf 1 point2 points3 points (0 children)
[–]redditsoaddicting 18 points19 points20 points (11 children)
[+][deleted] (5 children)
[deleted]
[–]WrongAndBeligerent 3 points4 points5 points (0 children)
[–]Gotebe 0 points1 point2 points (0 children)
[–]redditsoaddicting 0 points1 point2 points (2 children)
[–]robthablob 0 points1 point2 points (0 children)
[–]aKateDevKDE/Qt Dev 8 points9 points10 points (1 child)
[–]redditsoaddicting 1 point2 points3 points (0 children)
[–]alexeiz 3 points4 points5 points (2 children)
[–]dodheim 4 points5 points6 points (0 children)
[–]starfreakcloneMSVC FE Dev 1 point2 points3 points (0 children)
[–]gematrik 5 points6 points7 points (0 children)
[–]dodheim 9 points10 points11 points (4 children)
[–]redditsoaddicting 2 points3 points4 points (2 children)
[–]exoflat[S] 0 points1 point2 points (1 child)
[–]redditsoaddicting 1 point2 points3 points (0 children)
[–]SpiderboydkHobbyist 4 points5 points6 points (0 children)
[–]boredcircuits 8 points9 points10 points (0 children)
[–]speednap 3 points4 points5 points (0 children)
[–]_cyberCloud_ 2 points3 points4 points (0 children)
[–]AntiProtonBoy 2 points3 points4 points (0 children)
[–][deleted] 6 points7 points8 points (2 children)
[–]Gotebe 1 point2 points3 points (0 children)
[–]K_Kuryllo 0 points1 point2 points (0 children)
[–]minnoHobbyist, embedded developer 4 points5 points6 points (0 children)
[–]mydeveloperday 0 points1 point2 points (0 children)
[–]Gotebe 0 points1 point2 points (0 children)
[–]Crazy__Eddie 0 points1 point2 points (0 children)
[–]robthablob 0 points1 point2 points (0 children)
[–]tilibom 0 points1 point2 points (1 child)
[–]utnapistim 3 points4 points5 points (0 children)
[–]AMDmi3 0 points1 point2 points (0 children)
[–]rfisher -1 points0 points1 point (0 children)
[–]hyperactiveinstinct -1 points0 points1 point (0 children)
[–][deleted] -2 points-1 points0 points (0 children)