Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Accessors/modifiers naming convention

Reply
Thread Tools

Accessors/modifiers naming convention

 
 
Ook
Guest
Posts: n/a
 
      10-11-2005
Is there any kind of naming convention for accessor and modifiers? What I've
been doing is something like this:

// accessor
int getSize();

// Modifier
void setSize( int newsize);

private:
int _size;


 
Reply With Quote
 
 
 
 
Kristo
Guest
Posts: n/a
 
      10-11-2005
Ook wrote:
> Is there any kind of naming convention for accessor and modifiers? What I've
> been doing is something like this:


Naming conventions are a coding standards concept, which is something
not covered by the C++ standard. I believe the FAQ has links to a few
good ones that you could take a look at.

> // accessor
> int getSize();
>
> // Modifier
> void setSize( int newsize);


Sure, a lot of people name accessor/modifier functions this way.

> private:
> int _size;


Now *that* isn't allowed. Leading underscores are reserved for the
implementation. I suggest changing that to size_.

Kristo

 
Reply With Quote
 
 
 
 
Ook
Guest
Posts: n/a
 
      10-11-2005
>> private:
>> int _size;

>
> Now *that* isn't allowed. Leading underscores are reserved for the
> implementation. I suggest changing that to size_.
>
> Kristo


Seriously? I've always been taught that you should use leading underscores
for your private variables.


 
Reply With Quote
 
Kristo
Guest
Posts: n/a
 
      10-11-2005
Ook wrote:
> >> private:
> >> int _size;

> >
> > Now *that* isn't allowed. Leading underscores are reserved for the
> > implementation. I suggest changing that to size_.
> >
> > Kristo

>
> Seriously? I've always been taught that you should use leading underscores
> for your private variables.


You've been taught wrong. *Trailing* underscores, however, are a
common practice to indicate private member variables.

Kristo

P.S. Please attribute your quotes when posting a follow-up.

 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      10-11-2005
Ook wrote:
>>>private:
>>> int _size;

>>
>>Now *that* isn't allowed. Leading underscores are reserved for the
>>implementation. I suggest changing that to size_.
>>
>>Kristo

>
>
> Seriously? I've always been taught that you should use leading underscores
> for your private variables.
>
>


Technically no. Per 17.4.3.1.2/1, identifiers with a leading underscore
and a *LOWER CASE* letter are only reserved in the global and std
namespaces.

Per 17.4.3.1.2/1, identifiers witha leading underscore followed by an
UPPER CASE letter are reserved, period.

In either case, you're better off not using leading underscores at all.
 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      10-11-2005
In article < .com>,
Kristo <> wrote:
>Ook wrote:
>> Is there any kind of naming convention for accessor and modifiers? What I've
>> been doing is something like this:

>
>Naming conventions are a coding standards concept, which is something
>not covered by the C++ standard. I believe the FAQ has links to a few
>good ones that you could take a look at.
>
>> // accessor
>> int getSize();
>>
>> // Modifier
>> void setSize( int newsize);

>
>Sure, a lot of people name accessor/modifier functions this way.
>
>> private:
>> int _size;

>
>Now *that* isn't allowed. Leading underscores are reserved for the
>implementation. I suggest changing that to size_.


Not quite, there is some rules about how to use leading underscores,
and the above does not violate them as per any requirements of
Standard C++. However, it may violate other standards, or some
other convention, and besides, it's easier to not have to remember
the Standard C++ rules, so in short, the above is probably best
avoided, and instead some other convention be used (like trailing _'s)
if indeed some convention at all is necessary.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
 
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
Naming Convention for ASP.NET BAL/DAL? dm1608 ASP .Net 6 02-24-2006 07:25 PM
WS C3550 naming convention question frishack@gmail.com Cisco 2 02-23-2005 07:29 PM
JSP Method Naming Convention Buck Turgidson Java 1 03-02-2004 04:43 PM
Which c# naming convention? Rick ASP .Net 1 01-19-2004 11:42 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57