473,382 Members | 1,258 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,382 software developers and data experts.

thisIsAMemberFunctionName vs this_is_a_member_function_name

Is there any "standard" naming convention for member functions?
Which one should I prefer?

thisIsAMemberFunctionName
vs
this_is_a_member_function_name
Although most books and eminent authors (like Herb Sutter) recommend
the first approach, I certainly feel the second leads to more readable
names. In fact the STL itself uses the second naming convention.

Why then is the first convention usually recommended?

I understand that all this is strictly a matter of personal taste, but
since most of you guys here are pros, what do you all prefer?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #1
25 2343
I think it's important we all follow the same namming convention which is to
capitalize the first letter of each new word in the name as opposed to an
underscore. It's also important the function name suggests the action it
performs.i.e.

GetPrimeNumbers();
SortList();

JB

Jul 19 '05 #2
On 10 Nov 2003 01:47:10 GMT, jb********@aol.com (jbruno4000) wrote in
comp.lang.c++:
I think it's important we all follow the same namming convention which is to
capitalize the first letter of each new word in the name as opposed to an
underscore. It's also important the function name suggests the action it
performs.i.e.

GetPrimeNumbers();
SortList();

JB


Yes, but why do you feel that it is important not to have underscores?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Jul 19 '05 #3
Slash wrote:
Is there any "standard" naming convention for member functions?
Which one should I prefer?

thisIsAMemberFunctionName
vs
this_is_a_member_function_name


It is purely a stylistic issue, although the Standard Library prefers
the latter form.

Like almost all stylistic issues, it is far better to be consistent with
the other code on your team rather than to doing something uniquely
clever.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Too much agreement kills a chat.
\__/ Eldridge Cleaver

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #4
Slash wrote:
Is there any "standard" naming convention for member functions?
Which one should I prefer?

thisIsAMemberFunctionName
vs
this_is_a_member_function_name
Although most books and eminent authors (like Herb Sutter) recommend
the first approach, I certainly feel the second leads to more readable
names. In fact the STL itself uses the second naming convention.

Why then is the first convention usually recommended?

I understand that all this is strictly a matter of personal taste, but
since most of you guys here are pros, what do you all prefer?


The second version for function names, the first for class
names. Why because it is our house style. Otherwise it
doesn't matter. What does matter is that you stick to one
style or at the very least one style per class.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #5
de******@hotmail.com (Slash) wrote in message news:<34**************************@posting.google. com>...
Is there any "standard" naming convention for member functions?
Which one should I prefer?

thisIsAMemberFunctionName
vs
this_is_a_member_function_name
Although most books and eminent authors (like Herb Sutter) recommend
the first approach, I certainly feel the second leads to more readable
names. In fact the STL itself uses the second naming convention.

Why then is the first convention usually recommended?

I understand that all this is strictly a matter of personal taste, but
since most of you guys here are pros, what do you all prefer?


I prefer the first format. It doesn't really matter however, you'll get used
to it very quickly:
to make sure the whole team uses the same style is much more important.

Stephan

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #6
de******@hotmail.com (Slash) wrote in message news:<34**************************@posting.google. com>...
Is there any "standard" naming convention for member functions?
Which one should I prefer?

thisIsAMemberFunctionName
vs
this_is_a_member_function_name


Here's a coding convention that I follow:

* Capitalize class names LikeThis
* Use camel notation for methods sayLikeThis()
* Use all lowercase for variables like_this

Though the last style is most readable, the names quickly get too
long. So I prefer using that for the variables. Also, since most
method invocations are preceeded by a -> or ., the method names stand
out despite the starting character being in lower case. As for class
names - the capitalization has just stuck on :)

--
Tahir Hashmi (VSE, NCST)
http://www.codemartial.org
tahir AT ncst.ernet.in

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #7
Slash wrote:
Is there any "standard" naming convention for member functions?
No.
Which one should I prefer

thisIsAMemberFunctionName
vs
this_is_a_member_function_name
It depends. If your program is mainly based on a library or you are
writing additions to existing programs, use the one they used. If
you're doing something on your own, do what you prefer.
I think the first is used more often, and most often, I'm using it too.
Although most books and eminent authors (like Herb Sutter) recommend
the first approach, I certainly feel the second leads to more readable
names. In fact the STL itself uses the second naming convention.

Why then is the first convention usually recommended?
I don't know why it is recommended, but I don't consider one to be more
or less readable than the other. This might depend on the font of your
text editor though.
I understand that all this is strictly a matter of personal taste, but
since most of you guys here are pros, what do you all prefer?


I'm not sure that I'd already count as a pro, but one thing that you can
easily see in your example is that the names get a bit shorter using
the first method.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #8
I prefer the first because typing an underscore takes a little more
time. The underscore is a little off to the right and requires you to
move your hands to get to the key. If you just use letters, you can
type much faster.

In article <34**************************@posting.google.com >, Slash
<de******@hotmail.com> wrote:
Is there any "standard" naming convention for member functions?
Which one should I prefer?

thisIsAMemberFunctionName
vs
this_is_a_member_function_name
Although most books and eminent authors (like Herb Sutter) recommend
the first approach, I certainly feel the second leads to more readable
names. In fact the STL itself uses the second naming convention.

Why then is the first convention usually recommended?

I understand that all this is strictly a matter of personal taste, but
since most of you guys here are pros, what do you all prefer?


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #9
jbruno4000 wrote:
I think it's important we all follow the same namming convention which
is to capitalize the first letter of each new word in the name
as opposed to an underscore.
And for what reason do you think that?
It's also important the function name suggests the action it
performs.i.e.
Of course. Although calling them something like f1() to f2341() might be
fun if you love obfuscating your code :-)
GetPrimeNumbers();
SortList();

JB


Jul 19 '05 #10
On 9 Nov 2003 17:54:10 -0500, de******@hotmail.com (Slash) wrote in
comp.lang.c++:
Is there any "standard" naming convention for member functions?
Which one should I prefer?

thisIsAMemberFunctionName
vs
this_is_a_member_function_name
Although most books and eminent authors (like Herb Sutter) recommend
the first approach, I certainly feel the second leads to more readable
names. In fact the STL itself uses the second naming convention.

Why then is the first convention usually recommended?

I understand that all this is strictly a matter of personal taste, but
since most of you guys here are pros, what do you all prefer?


My personal preference is to have the underscores, whether or not you
capitalize the individual words or "wordlets".

I have notices that many C and C++ programmers do not seem to mind
underscores in variable names, but for some reason don't think they
should appear in function names.

My theory for their preference rests on two thoughts:

1. A long time ago, unique characters in identifier names were very
limited, to as little as 6 characters and a single case in early C
implementations.

2. The Windows API, which was written to be called by name from
languages like BASIC and Pascal and others that do not permit
underscores in identifier names, so defines all functions in
CamelCaseMode.

Interestingly enough, none of the programmers who allow underscores in
variable, enumeration, type, and macro identifiers but don't like them
in function names agree with my reasoning, even though some of them
have extensive Windows programming experience. But none of them has
ever proposed an alternate theory, either.

I have heard of studies alleging to prove that underscores improve
recognition greatly, but don't have any links handy.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #11
de******@hotmail.com (Slash) wrote in message news:<34**************************@posting.google. com>...
Is there any "standard" naming convention for member functions?
Which one should I prefer?

thisIsAMemberFunctionName
vs
this_is_a_member_function_name


In a sense a standard exists, in that the standard library uses the
second convention you describe. Apart from that, however, everyone has
his/her own favourite style, to the point that endless debates take
place periodically in this and other newsgroups. As I don't feel like
participating in such a debate today, I'll stick to "agnostic" advice:
Be consistent in your own code and try to agree to a project wide
standard. Which one doesn't matter much (unless you're working on a
project with me, in which case MY favourite style is the only possible
choice :-)

Cheers,
nicolaMusatti ;-)

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #12
I just like the idea of everybody following the same naming convention. It all
comes down to personal preference.
Jul 19 '05 #13
jbruno4000 wrote:
I just like the idea of everybody following the same naming
convention.


That might be a nice thing, but why do you think that it's so important
that it's the one you use? Just because you're too lazy to change? ;-)

Jul 19 '05 #14
This conversation has truly exausted itself!
Jul 19 '05 #15
Slash wrote:
Is there any "standard" naming convention for member functions?
No. This is purely a matter of style.
Which one should I prefer?

thisIsAMemberFunctionName
vs
this_is_a_member_function_name
this->functionName
Although most books and eminent authors (like Herb Sutter) recommend
the first approach, I certainly feel the second leads to more readable
names. In fact the STL itself uses the second naming convention.

Why then is the first convention usually recommended?

I understand that all this is strictly a matter of personal taste but,
since most of you guys here are pros, what do you all prefer?


The best advice that I can give you is

Keep a Thesaurus handy.

Choose short complete [English] words for function names,
constants, variables and types. Don't *mangle* them.
Try to avoid words like data, object, routine that have special meaning
or that are redundant in the context of a C++ program.

If you are writing scientific or engineering applications
you can implement long formulas with a single compact expression
using single character symbols annotated with comments:

// definition // nomenclature
// ---------------------------------------------------
double a = 9.8; // acceleration (meters/second/second)
double m = 1.0 // mass (kilograms)

double F = m*a; // force (Newtons)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #16
de******@hotmail.com (Slash) writes:
thisIsAMemberFunctionName
vs
this_is_a_member_function_name


Purely a matter of taste. But Stroustrup seems to prefer the latter
and I feel that if picking a style to emulate, the designer of the
language is probably the one to follow. Since the standard library
uses the second style (eg for_each not forEach) you might as well be
consitent with it.

But if you use a different class library, you might want to change
your style to fit in with that (eg MFC prefixes every class with 'C',
goodness knows why).

--
Ed Avis <ed@membled.com>

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #17
The style does not matter to me as long as it is consistent, but what
is annoying to me is whether or not to mix styles within a class that
is derived from a standard library component. I don't think a
universal coding style is not necessarily irrelevant as some people
portray. I don't think there is an absolute best objective style, but
having a universal coding style, which would include the standard
libraries and open source would be cool, well, as long as I like it ;)

Best,
John

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #18
Jason Carucci <jc******@yahoo.com> wrote in message
news:<091120032211566435%jc******@yahoo.com>...
In article <34**************************@posting.google.com >, Slash
<de******@hotmail.com> wrote:
> Is there any "standard" naming convention for member functions?
> Which one should I prefer? > thisIsAMemberFunctionName
> vs
> this_is_a_member_function_name > Although most books and eminent authors (like Herb Sutter)
> recommend the first approach, I certainly feel the second leads to
> more readable names. In fact the STL itself uses the second naming
> convention. > Why then is the first convention usually recommended? > I understand that all this is strictly a matter of personal taste,
> but since most of you guys here are pros, what do you all prefer?

I prefer the first because typing an underscore takes a little more
time. The underscore is a little off to the right and requires you to
move your hands to get to the key. If you just use letters, you can
type much faster.


And it is slightly easier to read with the underscores. Since code will
be read a lot more often than it is written, you should use underscores.
And of course, keyboard macros and word completion mean that there isn't
really any difference in typing, either.

In practice, with a little practice, the difference is negligible in
both case. Not enough really to base a choice on.

--
James Kanze GABI Software mailto:ka***@gabi-soft.fr
Conseils en informatique orientée objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #19


John Dill schrieb:
The style does not matter to me as long as it is consistent, but what
is annoying to me is whether or not to mix styles within a class that
is derived from a standard library component. I don't think a
universal coding style is not necessarily irrelevant as some people
portray. I don't think there is an absolute best objective style, but
having a universal coding style, which would include the standard
libraries and open source would be cool, well, as long as I like it ;)

Best,
John


A similar naming-convention dilemma exists, if you are going to specialize

template classes of std componets or if you want to provide a namespace
swap function, which could by used by std::algorithems (provided that
some yet unresolved swap issues **are** solved)

Greetings from Bremen,

Daniel


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #20
> But if you use a different class library, you might want to change
your style to fit in with that (eg MFC prefixes every class with 'C',
goodness knows why).


Well, how else would you know that it is a class? ;) I think it came
in through the hungarian notation that microsoft has supported so I
surmise that C=class?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #21
jb********@aol.com (jbruno4000) wrote
This conversation has truly exausted itself!


Yes, it was doomed from the start. It isn't quite a troll, but the
topic is one that's guaranteed to generate more heat than light;
not unlike a message asking what's the best computer language, or
why we don't all boycott Microsoft.

For the record: in my opinion, there are some issues where it's much
more important to have SOME standard, than anything that standard could
possibly say. When you're working with a group of programmers, you
should use the same indentation style, the same tab stops (or else only
use spaces), the same naming conventions, and so on. If your personal
code stands out in some way (other than comments with your name on it),
you're making maintenance much more difficult than it needs to be.

That means doing things even if you think they're stupid. If everyone
else uses "m_" in front of all member variables, you should do it too
even if you don't think it clarifies anything. On the other hand, if
nobody else does it you should refrain as well. If you really think
that everyone ought to be using "m_" in front of member variables,
propose it at a team meeting -- be prepared to explain why it's worth
fixing every line of code already written. (Or bring it up at the
beginning of the next project, before any code is written.)

The one exception to this philosophy is comments. AFAIK, nobody has ever
received negative feedback on their code because the comments were too
clear. My personal rule of thumb is to put a comment on almost EVERY
line of code, explaining why it's there (and assuming that all readers
already understand WHAT it does, so there's no point explaining it:
totProc += 17; // Add 17 to totProc
That comment does nothing useful, but
totProc += 17; // Update running count of orders processed
does, though you should now explain why 17 is the right value.)
Jul 19 '05 #22
Daniel Spangenberg <ds*@bdal.de> wrote in message
news:<3F***************@bdal.de>...
John Dill schrieb:
The style does not matter to me as long as it is consistent, but
what is annoying to me is whether or not to mix styles within a
class that is derived from a standard library component. I don't
think a universal coding style is not necessarily irrelevant as some
people portray. I don't think there is an absolute best objective
style, but having a universal coding style, which would include the
standard libraries and open source would be cool, well, as long as I
like it ;)

A similar naming-convention dilemma exists, if you are going to
specialize template classes of std componets or if you want to provide
a namespace swap function, which could by used by std::algorithems
(provided that some yet unresolved swap issues **are** solved)


Yes and no. swap, vector, string and map fit in with both schemes. And
who uses anything else:-).

Seriously, I sort of like having the library use a different convention.
That way, the reader knows to look in the standard, and not in my code,
for the documentation. Of course, the leading std:: should be a
sufficient give away.

In practice, the projects I've worked on have all used the second
convention for the project names, and having the standard library names
use a different convention doesn't seem to have ever bothered anyone.

--
James Kanze GABI Software mailto:ka***@gabi-soft.fr
Conseils en informatique orientée objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #23
jo*******@uiowa.edu (John Dill) wrote in message news:<30**************************@posting.google. com>...
But if you use a different class library, you might want to change
> your style to fit in with that (eg MFC prefixes every class with 'C',
> goodness knows why).


Well, how else would you know that it is a class? ;) I think it came
in through the hungarian notation that microsoft has supported so I
surmise that C=class?


<reposting as similar previous message seems to have got lost>

I thought it was a name conflict thing. If I am using the MFC library
I can use names like Bitmap, Button, View in my code if I want to
because the library only uses names like CBitmap, CButton, CView. I
believe Borland does a similar thing with its GUI development library,
starting all the class names with 'T', and wxWindows uses 'wx'.
Namespaces would be better, but I don't know whether namespaces were
available when these libraries started life.

This all falls down if you decide that starting class names with 'C'
is a really good idea because that's what Microsoft does.

GJD

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #24
Gavin Deane wrote:
jo*******@uiowa.edu (John Dill) wrote in message
news:<30**************************@posting.google. com>...
> But if you use a different class library, you might want to change
> your style to fit in with that (eg MFC prefixes every class with
> 'C', goodness knows why).
Well, how else would you know that it is a class? ;) I think it came
in through the hungarian notation that microsoft has supported so I
surmise that C=class?


<reposting as similar previous message seems to have got lost>

I thought it was a name conflict thing. If I am using the MFC library
I can use names like Bitmap, Button, View in my code if I want to
because the library only uses names like CBitmap, CButton, CView.
I believe Borland does a similar thing with its GUI development
library, starting all the class names with 'T', and wxWindows uses
'wx'.
Namespaces would be better, but I don't know whether namespaces were
available when these libraries started life.


That may be the reason why they are not used. But what does the C in
Microsoft's classes stand for?
This all falls down if you decide that starting class names with 'C'
is a really good idea because that's what Microsoft does.


I thought that Microsoft recommends to do that.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 19 '05 #25
Rolf Magnus <ra******@t-online.de> wrote
But what does the C in
Microsoft's classes stand for?


"Class", afaict.
This all falls down if you decide that starting class names with 'C'
is a really good idea because that's what Microsoft does.


I thought that Microsoft recommends to do that.


They do. That doesn't mean it's good advice.
(Name clashes and all that.)

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #26

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

Similar topics

2
by: Kari Laitinen | last post by:
During the past 15 years I have been writing computer programs with so-called natural names, which means that the names (identifiers, symbols) in progarms are constructed of several natural words....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.