J
Joe Greer
::
:: - When naming pointers should I append a prefix (pName, or
:: p_name), add a suffix (name_p) or nothing at all?
Think about what that will buy you. Is it important to always know
that something is a pointer? When you later realize that it should
have been a reference, will you change the name?
Pointers are easily recognized as they are used in expressions like
*Name, or Name->Something.
::
Well, personally, I think that pointerness is part of the name. I
always use pCar rather than car, because the variable
isn't a car it's a pointer to a car and a p is shorter that suffixing it
with ptr.
I developed my convention prior to having clever IDEs, so some of the
guidelines are there to help me find the variables. I still find it
convenient to know at a glance where things are coming from during the
maintenance phase of development, so I haven't adjusted it much.
I generally use camel case for naming items.
Variables start with a lower case letter (This rule includes any
prefixes as part of the variable name, thus car, m_Car, m_pCar, pCar etc
are all variables).
Members get prefixed with m_.
Statics are prefixed with an s_
Globals (if any) get prefixed with a g_.
Locals don't get a prefix because they should be declared nearby and are
easily found.
Functions, class names and constants start with a capital letter
(MaxSize, SomeClass).
I haven't really formed a strong preference for
namespaces. So far, I have kept them lowercase and sometimes with '_'s
instead of camel case. I suppose for consistency, I should prefer camel
case starting with a capital (like classes), but I create far fewer
namespaces than classes, so I haven't developed a strong preference.
Now for some anti patterns:
I really really don't like trailing '_'s or even prefixes because they
look horrible in actual code. Things like carptr_->engine_ just look
weird to me and so does _carptr->_engine. Just too many straight lines
in a row. But, that's just my opinion.
Hope that helps more than adds to the confusion.
joe