I was just wondering what naming convention most of you use for class
variables.
Underscore, "m_" prefix, camel case, capitalized, etc?
Has one style emerged as the most popular?
Thanks for any comments.
It depends upon several things. The most important of which is your code's
complexity.
If your code writing exhibits a tendency towards writing smaller methods
which in turn call other small method, and they don't have many arguments
you are less likely to be in need of a strong naming schema. Then again, if
you work in a team and the team is not particularly experienced, you may be
in need of a strong naming schema. Personally, for all of the 'at work'
code I wrote, I use a very strong naming schema left over from my Microsoft
days and I require my team to use it as well, in some ways this is a pain in
the a** for the developers, but anybody can read anybody else's code far
more easily than when I didn't require this level of discipline. For
consulting work, I simply use whatever standards the customer requires (they
usually have coding groups and standards already) so that my code fits right
in.
It's all toolbox and people tend to get zealous about little things like
that (and languages for instance
.)
Example of a strong schema?
Can you tell which elements in the method signature below are incoming
and/or outgoing?
bool LocalizeMenuResource( string in_strMenuName, unsigned int
in_nResourceID, string out_strLocalizedText )
An example of a strong class member name 'string m_strDBConnectionString'
One of the things I constantly strive to avoid doing myself is writing
abbreviated variable names unless it is an extremley obvious word like 'DB'.
Sometimes this can look ridiculous; however, many times I've had new team
members comment on how easy it is to understand what the code is doing
because of this. It appears to make more impact on people who know less
about the codebase than those who already have a general feel for what's
going on and how each team members contributes code.
Again, it primarily depends on your style of coding, what type of team
you're in, the dynamism of that team, et cetera. These are all things, btw,
that should effect your methodology as a whole as well.
WTH