[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
More Coding Convention
In the coding convention doc, it says that it is free for people to indicate
that variables are member variables either by prefixing "m_", or making the
first letter of the variable upper case.
IMHO, that's not a very good idea. That way, you'd have to check all the
time what convention was used by the guy who first wrote the class. That's
not very cool for readability.
I think we need to agree on one or the other.
Notice that I've used the convention of prefixing "m_" for a very long time,
and I'm used to see it in all the libs I use, so I'm completely and
throughfully impartial here :)
I think prefixing "m_" is much better than making the first letter upper
case for these reasons:
-Suppose I write this "ThisIsSomething" in my code. Now, is this a
member-variable, or is it a function or a method? I can't tell you, I'll
have to look. Of course, in most cases, its pretty obvious if its a variable
or a function, but in some cases it might not be, and its none-the-less not
good for reading code at a glance.
- Try and find the 4 variables in in these variable that are non-member
functions:
someVariable someVariable someVariable someVariable someVariable
someVariable
someVariable someVariable someVariable someVariable SomeVariable
someVariable someVariable
someVariable SomeVariable someVariable someVariable someVariable
someVariable
someVariable someVariable someVariable someVariable someVariable
someVariable someVariable someVariable someVariable SomeVariable
someVariable someVariable someVariable someVariable
someVariable someVariable someVariable someVariable SomeVariable
someVariable
Now try and do the same for this:
someVariable someVariable someVariable someVariable someVariable
someVariable
someVariable someVariable someVariable someVariable m_someVariable
someVariable someVariable
someVariable m_someVariable someVariable someVariable someVariable
someVariable
someVariable someVariable someVariable someVariable someVariable
someVariable someVariable someVariable someVariable m_someVariable
someVariable someVariable someVariable someVariable
someVariable someVariable someVariable someVariable m_omeVariable
someVariable
Now, if you actually took the time to do it, you will find that its ALOT
easier to spot the m_someVariable than the SomeVariable, which makes it
easier to read code at a glance.
-Try look at this and spot the variable declaration
class ppSomeClass
{
int SomeMemberThatReallyIsAMethod();
int SomeMemberThatIsSomething();
int SomeMemberThatsSomething;
int SomeMemberThatsSomethingReally()
}
Now do the same for this:
class ppSomeClass
{
int SomeMemberThatReallyIsAMethod();
int SomeMemberThatIsSomething();
int m_someMemberThatsSomething;
int SomeMemberThatsSomethingReally()
}
See what I mean? Again, its much easier to spot the variable if its prefixed
with "m_". Now, of course, variables and methods are normally not declared
together like this, but that doesn't change the fact that its still easier
to spot the variable that's prefix with "m_" than the variable that has had
its first letter changed to upper case.
-Its also easier to figure out, by somebody that doesn't know or has
forgotten, what's meant by "m_" that it is to figure out what's meant by
making the first letter upper case. "m_" is m as in 'm'ember.