thisIsAMemberFunctionName vs this_is_a_member_function_name

S

Slash

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?
 
J

jbruno4000

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
 
J

Jack Klein

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
 
E

Erik Max Francis

Slash said:
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.
 
L

lilburne

Slash said:
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.
 
S

Stephan Br?nnimann

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
 
T

Tahir Hashmi

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 :)
 
R

Rolf Magnus

Slash said:
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.
 
J

Jason Carucci

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

Rolf Magnus

jbruno4000 said:
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 :)
 
J

Jack Klein

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
 
N

Nicola Musatti

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 ;-)
 
J

jbruno4000

I just like the idea of everybody following the same naming convention. It all
comes down to personal preference.
 
R

Rolf Magnus

jbruno4000 said:
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? ;-)
 
E

E. Robert Tisdale

Slash said:
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)
 
E

Ed Avis

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

John Dill

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
 
K

kanze

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

Daniel Spangenberg

John said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,375
Latest member
FelishaCma

Latest Threads

Top