Re: Naming conventions
Miguel Guedes wrote:
:: Victor Bazarov wrote:
::: Ah... Um... All names are lowercase. Multi-word names have words
::: separated by underscores (random_shuffle, push_back, find_if).
::: It's not as consistent as many would like, though. E.g.
::: "getline" is
::: a single "word", no underscores (and there are other examples like
::: that).
:::
::: Don't get hung up on a specific naming convention. Pick one that
::: is convenient and be consistent with it.
:::
::: V
::
:: Trouble is I have many questions I've not been able to find
:: convincing answers to. For instance:
::
:: - 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.
::
:: - Should I name namespaces in all-lowercase letters or follow
:: class name conventions (all words start with uppercase)?
You should probably just use one way of creating names. Otherwise you
risk getting names that just differs by case.
namespace car
{
class Car;
}
Now you have
car::Car // a type
Car::Car // a constructor
Not good!
::
:: - What about global and static variables? Should I append a prefix
:: 'glo' and 'sta' respectively, as the guidelines in Boost.org
:: recommend?
You probably shouldn't use many of these in the first place! :-)
If you need some global configuration settings, for example, you can
put them in a namespace and get code like:
if (Global::Config::ShowDebugInfo)
{
// display something interesting
}
::
:: I won't bore you to death. This is just an illustration of how much
:: unsure I am when it comes to naming conventions.
So are we. And nobody agrees anyway!
Use readable names!
::
:: In all honesty, the reason why I started this thread was because
:: I'm still using remnants of Microsoft's crippled god-awful
:: hungarian notation (professional obligation) and want to
:: completely get rid of all the inconsistencies it introduces.
That was somewhat useful once upon a time, to simulate type checking
when C types were really just typedefs. In C++ the compiler will tell
you not to mix two incompatible classes in the same expression.
:: So,
:: seeing I'm about to start anew, I thought that there's nothing
:: better than to follow _proper_ standards - the ones specified in
:: C++ standards.
And there aren't any. :-(
Bo Persson