ISO Studies of underscores vs MixedCase in Ada or C++

I

Isaac Gouy

I am in search of any rigourous,
scientific, academic or industrial studies
comparing naming conventions in
C++ or similar languages such as
Ada:

- SNIP -
I hope it is obvious why I have chosen these
newsgroups to post this search to:

comp.software-eng, comp.programming,
- an issue of software engineering
comp.lang.c++,
- the language I am most interested in
comp.lang.ada
- because I vaguely recall historical work

Maybe the "Psychology of Programming Interest Group" mailing list
would be a good place to ask?
http://www.ppig.org/lists.html
 
P

Programmer Dude

Peter said:
You've piqued my interest, since I'm the first to admit that my
grammar specifications are hard to read.

Where do you put the action in the above code?

classmethod :
access_specifier
method_type_specifier
method_return_type_specifier
method_declaration
method_body
{ doSomething(); }

I thought this was a grammar definition? I'd have thought that

method_body :== { doSomething(); }

But if they are different, the way you did it seems fine to me.
What if there's more than one reduction possible?

classmethod :
access_specifier
method_type_specifier
method_return_type_specifier
method_declaration
method_body
{ doSomething(); }
| something_else
another_thing
even_more
blah_blah
{ doSomethingElse(); }

Probably break them up in some fashion:

class-method:
class-method-normal |
class-method-extended

class-method-normal:
access-specifier
method-type-specifier
method-return-type-specifier
method-declaration
method-body

class-method-extended:
something-else
another-thing
even-more
blah-blah

Agreed! I wish that more languages allowed hyphen use in
identifiers. Dylan is the only one I can think of off the
top of my head.

Others have already mentioned Lisp, so I don't have to!
(Well,... *didn't* have to... :)
 
S

Stephen Baynes.

takeAction(doYouMind.ifI(openTheWindow));
take_action (do_you_mind.if_i (open_the_window));

take_Action (do_You_Mind.if_I(open_The_Window));

Take_Action (Do_You_Mind.If_I (Open_The_Window));

Once you start looking at the readability whole expressions, you also need
to look at the use of spaces. The above are not consistant about if a space
is used with round brackets. [And then there is the question - is it more
readable with the space outside or inside the bracket - my preference is for
inside - so the opening bracket is with the function name rather than the
first parameter.]
Take_Action (Do_You_Mind.If_I (Open_The_Window));
Take_Action(Do_You_Mind.If_I(Open_The_Window));
Take_Action( Do_You_Mind.If_I( Open_The_Window ) );

To go back to the original question - there have been studies that showed
underscores gave the most readable results - unfortunately I have lost the
reference and I would also like to get my hands on it again.

-
Stephen Baynes CEng MBCS
My views are my own

news:[email protected]...
 
J

Jakob Bieling

Jacob Sparre Andersen said:
Why. They are hopefully spelled correctly. Otherwise you are adding an
unneeded complication to reading and understanding your code.


I wouldn't like that. Incorrectly spelled identifiers make code
maintenance more difficult.

I do not know how you choose your identifier names, but I usually give
them abbreviated prefixes, which would make every spell-checker flag a
misspelling. See Kevin's example (
Would certainly be nice. But doing a proper job here basically means
trying to compile the code. If you decide to ignore visibility rules,
things will of course become much simpler.

Right. You got me thinking here, though. Since the code is
sort-of-spell-checked by the compiler already, point a and b are pretty much
superflous (unless you want the luxury of the compiler trying to guess the
correctly spelled identifier name). No need for a special spell-checker
anymore, except that it should only spell-check comments ;)

regards
 
M

Mike Wahler

Jakob Bieling said:
correctly spelled identifier name). No need for a special spell-checker
anymore, except that it should only spell-check comments ;)

I often refer to identifier names in my comments,
so back to the original problem. :)

-Mike
 
G

Georg Bauhaus

: Once you start looking at the readability whole expressions, you also need
: to look at the use of spaces. The above are not consistant about if a space
: is used with round brackets.

Glad someone noticed, explicitly :) Has anybody written Algol
programs (using spaces in identifiers)?


Georg
 
J

Jacob Sparre Andersen

Jakob said:
I do not know how you choose your identifier names, but I usually give
them abbreviated prefixes,

I practically never use abbreviations or acronyms in identifiers -
except for those from the project specific "approved" list ("IO" is
always there, though :). And when I do, it is always as separate parts
like in "Integer_Text_IO". I would never write "IntegerTextIO",
"intTextIO" or "Int_Text_IO" in my code.

If you want more details on how I choose my identifier names, then
chapter 3 in »Ada Quality and Style« is hopefully a good description.

Greetings,

Jacob
 
J

Jakob Bieling

Jakob Bieling wrote:
I practically never use abbreviations or acronyms in identifiers -


Not sure where I picked that habit up, but I guess it is pure laziness.
I could not imagine having to type those long names everytime you use them.
Especially counter variables in for-loops (posting from comp.lang.c++) ..
you also use simple i's and j's etc. there, right? As you seem to be posting
from comp.lang.ada, I am not too sure if Ada provides such constructs in the
same way C++ does, so maybe Ada has different means of looping in a
for-loop-kind-of-way (yes, I know pretty much nothing about Ada).

Also, sometimes I tend to abbreviate quite a lot, so that later I might
not know what it stands for. In cases like those I just put a comment next
to where I declared the variable and I can keep saving those keystrokes.

regards
 
J

Jakob Bieling

Mike Wahler said:
I often refer to identifier names in my comments,
so back to the original problem. :)


Ok, so we do need a scope-less list of identifier names :p
 
P

Peter Bushell

Jakob Bieling said:
Also, sometimes I tend to abbreviate quite a lot, so that later I might
not know what it stands for. In cases like those I just put a comment next
to where I declared the variable and I can keep saving those keystrokes.

If you can't remember what it meant, pity the poor engineer who has to
maintain your code when you've gone! Having to look up a declaration every
few seconds is not acceptable.

There is evidence* to suggest that 80% of programming is (or should be)
thinking time. Saving keystrokes is therefore not an issue.

Regards,

Peter Bushell.

* My source was Glass, Robert L., "Facts and Fallacies of Software
Engineering". His source was some research material published in another of
his books: "Software Creativity".
 
J

Jakob Bieling

If you can't remember what it meant, pity the poor engineer who has to
maintain your code when you've gone! Having to look up a declaration every
few seconds is not acceptable.

You do not have to. All declarations (loop counters etc. are an
exception) are at the beginning of the function, along with possible
comments. And for those identifiers where comments are necessary, I do not
think it is impossible to remember them.
There is evidence* to suggest that 80% of programming is (or should be)
thinking time. Saving keystrokes is therefore not an issue.

True, but it is still pretty annoying to type all kinds of variable
names out (we are talking about long names, anything over 10 letters,
right?) all the time you use them. The 'burden' of remembering 5 or 6 names
for which you always see the abbreviations is less, in my opinion.

To avoid misunderstandings, I do not approve using abbreviations for all
kinds of variables. But I do find it acceptable to use my way of
abbreviating (including comments) for function local variables.

hth
 
A

Alan Balmer

True, but it is still pretty annoying to type all kinds of variable
names out (we are talking about long names, anything over 10 letters,
right?) all the time you use them

A good editor can eliminate that problem.
 
B

brougham5

Jakob Bieling said:
Not sure where I picked that habit up, but I guess it is pure laziness.
I could not imagine having to type those long names everytime you use them.

Neither can I. I rarely abbreviate in a variable name. But I rely on code
completion in my editor to save typing those keystrokes.

The problem is that once you start abbreviating, odds are some abbreviations
are not going to be consistent. I've seen nbr, no, nu, or num instead of
number. Using an editor that will complete nu to number might make your
life easier in a multi-person project.

That said, I'll use cachedUrl over the non-abbreviated form, but that's
because I expect most people to abbreviate URL the same way.
 
J

Jakob Bieling

Alan Balmer said:
A good editor can eliminate that problem.


For function local variables, mine does not. For class members or
identifiers in a namespace it does.

regards
 
J

Jakob Bieling

them.

Neither can I. I rarely abbreviate in a variable name. But I rely on code
completion in my editor to save typing those keystrokes.

As a said in the other post: For function local variables, mine does not
have that feature.
The problem is that once you start abbreviating, odds are some abbreviations
are not going to be consistent. I've seen nbr, no, nu, or num instead of
number. Using an editor that will complete nu to number might make your
life easier in a multi-person project.

Yes, I do write 'num' instead of number. Or I also write 'msg' instead
of message, or 'ips' for an 'InterProcessSynchronisation' handle. In case of
ips, I might not know what it is without context. But when seeing that
variable used in a function call, it is clear what it is supposed to be.
Along with the comments in the code, I find it justified and not overly hard
to read.

regards
 
A

Alan Balmer

For function local variables, mine does not. For class members or
identifiers in a namespace it does.
Mine will complete any symbol it knows about, or give you a drop-down
list if there's more than one choice. However, almost any editor will
allow you to code with abbreviations, then expand them to full names
with search and replace. This can be useful for some people who have
total recall in the heat of a programming session, but can't remember
what they were thinking a week later :)
 
F

Frank Schmitt

Jakob Bieling said:
For function local variables, mine does not. For class members or
identifiers in a namespace it does.

But why would you want to make function local variables' names more than
10 letters long?
My local variable names tend to consist of only one word, e.g

OutputStreamWriter writer;

Or are your functions so long that you need longer variable names?

regards
frank
 
J

Jacob Sparre Andersen

James said:
CamelMode, camel_mode, etc. are all quite *readable*;

It may be a matter of personal taste (haven't seen any actual studies),
but I prefer underscores between words, when I am no allowed to put
spaces there. In Ada I follow the style guide and use both underscores
and capitalisation.
when using long
names the important thing is to make them *writable*,

Try to count how often you _read_ and _write_ an identifier. I think
you might be surprised by the difference. Easy writing of the
identifers is not anywhere nearly as important as easy reading.
Consistency is therefore the important thing.

It is.
If you abbreviate words,
abbreviate them as the first 4 (or whatever) letters, consistently.

I prefer the suggestion from the Ada style guide (IIRC) that you don't
abbreviate words, and that you only use acronyms from a limited
project-specific list.
(I usually rewind a file with "lseek(fd, 0L, 0)" because I can't
remember if 0 is SEEKSET or SEEK_SET.)

Very annoying with a standard library with an inconsistent naming of
identifiers.

One more point on the topic of consistent naming of identifiers. I find
the style with using different naming conventions for functions,
constants, variables, etc. very annoying. I _don't_ want to have to
worry if something is a function, constant or variable. Specially not
if it actually is an implementation dependent detail. So _please_ use
the same naming convention for all identifiers.

Jacob
 
J

Jacob Sparre Andersen

Jakob said:
True, but it is still pretty annoying to type all kinds of variable
names out

I suppose I should thank my mother for insisting that I learned how to
use a typewriter.
To avoid misunderstandings, I do not approve using abbreviations for all
kinds of variables. But I do find it acceptable to use my way of
abbreviating (including comments) for function local variables.

Do non-local variables really exist? :)

But yes, if you make sure that the declaration of the variables is
always immediately visible, when one is observing their use, then I can
understand your argument (although I still don't approve of it).

Jacob
 
J

Jacob Sparre Andersen

Jakob Bieling wrote:

[ abbreviated identifier prefixes ]
Not sure where I picked that habit up, but I guess it is pure laziness.
I could not imagine having to type those long names everytime you use them.

Well. I tend to read code more often than I write it (even my own), and
most of my time is spent thinking about what to write, so saving a few
keystrokes really doesn't make sense to me.
Especially counter variables in for-loops (posting from comp.lang.c++) ..
you also use simple i's and j's etc. there, right?

No. (unless it is for matrix and tensor manipulation, where the
"documentation" actually says "i", "j" and "k")
As you seem to be posting from comp.lang.ada,

Well. There and "comp.software-eng".
I am not too sure if Ada provides such constructs in the
same way C++ does, so maybe Ada has different means of looping in a
for-loop-kind-of-way (yes, I know pretty much nothing about Ada).

The Ada for loop is not as flexible/error-prone as I remember the C++
for loop (which I haven't had to use for years :). A quick example:

for Day in Monday .. Friday loop
Put (Day); Put_Line (" is a workday.");
end loop;

(where I assume I have declared an enumerated type based on the days of
the week). The counter variable is created by the for loop statement,
so you don't have to worry about making an explicit declaration of a
variable for use as the counter. I seem to remember that you have to
have an explicit declaration of the counter variable in C++, which of
course makes a slight difference.
Also, sometimes I tend to abbreviate quite a lot, so that later I might
not know what it stands for.

Not good. That costs time and is a potential source for errors if you
misremember the meaning of the abbreviation.
In cases like those I just put a comment next
to where I declared the variable and I can keep saving those keystrokes.

I consider that a misuse of comments. I see comments as a means for
expressing what _can_ not be expressed in actual code. Otherwise you
risk ending up with code and comments that say different things. One
result of this view is of course that it differs from language to
language, what are reasonable comments.

My main worry with long identifier names is that they shouldn't make the
lines so long that they become incomprehensible.

Jacob
 

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
473,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top