473,395 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Accessors/modifiers naming convention

Ook
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;
Oct 11 '05 #1
5 2416
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

Oct 11 '05 #2
Ook
>> 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.
Oct 11 '05 #3
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.

Oct 11 '05 #4
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.
Oct 11 '05 #5
In article <11**********************@g47g2000cwa.googlegroups .com>,
Kristo <kr*******@gmail.com> 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?
Oct 11 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Generic Usenet Account | last post by:
A lot has been said in this newsgroup regarding the "evil" set/get accessor methods. Arthur Riel, (of Vanguard Training), in his class, "Heuristis for O-O Analysis & Design", says that there is...
14
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them......
0
by: Carl Colijn | last post by:
Hi all, Disclaimer: before I might trigger your "let's start a holy war!" button, I'd like to say I'm not intended to; I just post this message to get some input and not to promote "Yet Another...
10
by: jjkboswell | last post by:
I'm trying to pin down a good naming convention for the 3 things required to implement an event. You need: 1) a delegate 2) an event 3) an event handler Below is my understanding of a...
6
by: dm1608 | last post by:
I'm relatively new to ASP.NET 2.0 and am struggling with trying to find the best naming convention for the BAL and DAL objects within my database. Does anyone have any recommendations or best...
4
by: Sturdy | last post by:
Hi, I'm new to C# and .NET. I'm a first time user of Visual C# 2005 Express and have a very basic question. I've looked at several links and lots of docs but can't find any tips on naming multiple...
3
by: rsine | last post by:
I have searched around a little and have yet to find a naming convention for the string builder object. I really do not want to use "str" since this is for string objects and thus could be...
114
by: Jonathan Wood | last post by:
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...
35
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.