Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Naming conventions

Reply
Thread Tools

Naming conventions

 
 
Miguel Guedes
Guest
Posts: n/a
 
      08-22-2007
Hello,

Does anyone have a link to the C++ Standard Library naming conventions
that they could share? I have found a few links to pages on C++ naming
conventions but am unsure as to what standard they follow.

Best Regards,

-- Miguel Guedes

- X marks the spot for spammers. If you wish to get in touch with me by
email, remove the X from my address. -
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-22-2007
Miguel Guedes wrote:
> Does anyone have a link to the C++ Standard Library naming conventions
> that they could share? I have found a few links to pages on C++ naming
> conventions but am unsure as to what standard they follow.


What do you need it for? If you want to know what's allowed to be used,
get a copy of the Standard, and see what's not allowed; everything else
would be OK. All names visible to the programmer are defined in the
Standard already. You're not supposed to add any. If you need to know
what functions/objects/types exist, get yourself a reference manual.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Miguel Guedes
Guest
Posts: n/a
 
      08-22-2007
Victor Bazarov wrote:
> Miguel Guedes wrote:
> What do you need it for? If you want to know what's allowed to be used,
> get a copy of the Standard, and see what's not allowed; everything else
> would be OK. All names visible to the programmer are defined in the
> Standard already. You're not supposed to add any. If you need to know
> what functions/objects/types exist, get yourself a reference manual.
>
> V


I'm sorry for not making myself clear, Victor.

I'd like to adopt standard compliant naming conventions and thought that
the best way to do it would be to read up on the C++ standard naming
conventions. Boost.org, for instance, recommends this.

I found a link [1] but, seeing the standards presented on the page are
_derived_ from the C++ Coding Standards, I'm unsure what to make of it...


[1] http://www.nws.noaa.gov/oh/hrl/ihfs/...C++_naming.htm

--
Miguel Guedes

- X marks the spot for spammers. If you wish to get in touch with me by
email, remove the X from my address. -
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      08-22-2007
Miguel Guedes wrote:
> Victor Bazarov wrote:
>> Miguel Guedes wrote:
>> What do you need it for? If you want to know what's allowed to be
>> used, get a copy of the Standard, and see what's not allowed;
>> everything else would be OK. All names visible to the programmer
>> are defined in the Standard already. You're not supposed to add
>> any. If you need to know what functions/objects/types exist, get
>> yourself a reference manual.
>>
>> V

>
> I'm sorry for not making myself clear, Victor.
>
> I'd like to adopt standard compliant naming conventions and thought
> that the best way to do it would be to read up on the C++ standard
> naming conventions. Boost.org, for instance, recommends this.
>
> I found a link [1] but, seeing the standards presented on the page are
> _derived_ from the C++ Coding Standards, I'm unsure what to make of
> it...
>
>
> [1] http://www.nws.noaa.gov/oh/hrl/ihfs/...C++_naming.htm


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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
Miguel Guedes
Guest
Posts: n/a
 
      08-22-2007
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?

- Should I name namespaces in all-lowercase letters or follow class name
conventions (all words start with uppercase)?

- What about global and static variables? Should I append a prefix 'glo'
and 'sta' respectively, as the guidelines in Boost.org recommend?

I won't bore you to death. This is just an illustration of how much
unsure I am when it comes to naming conventions.

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. 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.


--
Miguel Guedes

- X marks the spot for spammers. If you wish to get in touch with me by
email, remove the X from my address. -
 
Reply With Quote
 
Bo Persson
Guest
Posts: n/a
 
      08-22-2007
Miguel Guedes wrote:
:: Victor Bazarov wrote:
::: Miguel Guedes wrote:
::: What do you need it for? If you want to know what's allowed to
::: be used, get a copy of the Standard, and see what's not allowed;
::: everything else would be OK. All names visible to the programmer
::: are defined in the Standard already. You're not supposed to add
::: any. If you need to know what functions/objects/types exist, get
::: yourself a reference manual.
:::
::: V
::
:: I'm sorry for not making myself clear, Victor.
::
:: I'd like to adopt standard compliant naming conventions and
:: thought that the best way to do it would be to read up on the C++
:: standard naming conventions. Boost.org, for instance, recommends
:: this.
::
:: I found a link [1] but, seeing the standards presented on the page
:: are _derived_ from the C++ Coding Standards, I'm unsure what to
:: make of it...
::
::
:: [1]
:: http://www.nws.noaa.gov/oh/hrl/ihfs/...C++_naming.htm
::
:: --

The standard doesn't have a naming convention. Different chapters of
the standards document have different authors, and they don't agree
completely either on style or on namning.

Your link points to two reasonable and widespread conventions,
lowercase and underscore, or uppercase letters as word separators.
That gives you either get_line(), or GetLine(). Choose one, and stick
to it!

I do not at all believe in using prefixes, like ref or ptr, or using
an upper or lower case first letter to differentiate between different
types of objects.


Bo Persson


 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      08-22-2007
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?
>
> - Should I name namespaces in all-lowercase letters or follow class
> name conventions (all words start with uppercase)?
>
> - What about global and static variables? Should I append a prefix
> 'glo' and 'sta' respectively, as the guidelines in Boost.org
> recommend?
>
> I won't bore you to death. This is just an illustration of how much
> unsure I am when it comes to naming conventions.
>
> 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. 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.


You're a bit mistaken here. The C++ Standard does NOT specify any
naming convention. It tries to follow some, but isn't doing a good
job, either.

Cleaning out inconsistencies is a good goal to have, unfortunately
it's an unattainable one. Even if you do a piece-meal by collecting
different conventions from more than one style guide, you will likely
end up with some sort of inconsistency or two. There is no escape.

The rule of thumb here is "try to be simple, as simple as possible,
but not simpler". If you think you need prefices, use them. Which
ones? Who cares? You just need to be consistent. 'p' for pointers,
'g' for globals, 'm' for members... It does not matter. The
Standard Library and the language proper does not use many prefices,
but it uses suffices, like '_t' for new types (size_t, ptrdiff_t).
Is that better? Not sure. Not all types have _t on them either.

Here is my final advice: take _a_ convention and write it down. Try
to reduce the number of rules you have in your style guide. If you
can, have no more than, say, five rules. If in the process of
following your own style guide you find that you need to introduce
more rules, try to resist the temptation becuase it may mean you'll
need to review previously written code, where you didn't follow
the same new rules. IOW, the style guide should be (a) a *guide*
not a *law*, and (b) *descriptive* more than *perscriptive*.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
Gianni Mariani
Guest
Posts: n/a
 
      08-22-2007
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?
>
> - Should I name namespaces in all-lowercase letters or follow class name
> conventions (all words start with uppercase)?
>
> - What about global and static variables? Should I append a prefix 'glo'
> and 'sta' respectively, as the guidelines in Boost.org recommend?
>
> I won't bore you to death. This is just an illustration of how much
> unsure I am when it comes to naming conventions.
>
> 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. 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.


I have a naming convention for you.

Pick names that mean somthing useful.

e.g., I don't find it useful to prepend "p" for pointer, but I do find
it useful to prepend "s_" for static, or "w_" for template parameter or
"m_" for member variable - but not for function names.

The convention I usually use is:

When declaring function parameters do:
i_ - input
o_ - output
io_ - input/output

Class members:
t_ - type
m_ - member
s_ - static member

Templates
w_ - template parameter

Other decls
g_ - global variable
l_ - local variable


This does help me disambiguate some cases - like:

struct A
{
int m_val;
A( int i_val ) : m_val( i_val ) {}
};


Make sense ?
 
Reply With Quote
 
=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      08-22-2007
On 2007-08-22 22:41, 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?


Use names that makes sense, it's often more important to know what it
points to than that it's a pointer. Most IDEs can tell you the type of a
variable but they can not tell you what the value represents.

> - Should I name namespaces in all-lowercase letters or follow class name
> conventions (all words start with uppercase)?


As previously pointed out, the classes etc. in the standard library use
underscores and not camel-case. Personally I like camel-case better but
Bjarne Stroustrup claims that underscores have been proven to be more
readable.

> - What about global and static variables? Should I append a prefix 'glo'
> and 'sta' respectively, as the guidelines in Boost.org recommend?


You should avoid globals

> I won't bore you to death. This is just an illustration of how much
> unsure I am when it comes to naming conventions.
>
> 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.


If you try to get rid of MS's Hungarian notation then why do you try to
put it back in with prefixing stuff. The original Hungarian notation
used prefixes to indicate what type of data was stored, not the type of
the variable used to store them, i.e. szWidth indicates that the
variable contains the size of something.

> 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.


There is no formal C++ naming convention used by the standards committee
(AFAIK) but they do try to keep things consistent but I'm quite sure
that there are inconsistencies, some due to backward compatibility no
doubt. If you are looking at for a standard you'll probably have better
luck looking at Java and .Net, for frameworks that large I'm sure they
have worked out some standard.

Get something that feels comfortable and start to write a list of how
you should name stuff, when you can no longer come up with any more
cases start using the standard and fix the remaining cases as they come
up. It does not matter what standard you use, because I can almost
guarantee that none else will used the same standard, there are always
some corner cases where they differ.

--
Erik Wikström
 
Reply With Quote
 
Bo Persson
Guest
Posts: n/a
 
      08-22-2007
Gianni Mariani wrote:
:: Miguel Guedes wrote:
:::
::: 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. 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.
::
:: I have a naming convention for you.
::
:: Pick names that mean somthing useful.

Good idea!!

::
:: struct A
:: {
:: int m_val;
:: A( int i_val ) : m_val( i_val ) {}
:: };
::
::
:: Make sense ?

Personally I don't like all the underscores and little separate
characters.

I have a hypothesis that there might be some cultural preferences
between people using get_line() and GetLine(). Scandinavians and
germans, for example are very used to create new words by appending a
number of smaller words. We do that all the time, IRL! English and
americans do not, and that might make them prefer to write
lots_of_little_words_with_undescores. I find that hard to read!

struct A
{
int Value;
A(int Init) : Value(Init) {}
};



Bo Persson


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Web.conf debug attribute creates different control naming conventions .NET 1.1 Roy Assaly ASP .Net 1 04-10-2006 07:59 PM
Me vs. .NET HTML Control naming conventions Josh Wolf ASP .Net 2 03-31-2006 12:37 PM
Namespaces and Naming conventions Floppy Jellopy ASP .Net 4 07-21-2005 01:36 PM
Naming conventions for ASP.NET objects? =B= ASP .Net 4 09-06-2004 09:05 AM



Advertisments