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

M

Mad Hamish

Underscores are basically a way to provide spaces in an identifier. Since
identifiers are generally phrases (nown phrases for objects, verb phrases
for procedures) and phrases often consist of more than one word, I find the
use of underscores to be quite natural.

The opposing argument is that underscores are too large, and that a case
change is a more readable way to indicate how to divide the decomposition
into words. To me, the upper / lower case method of delineate the words in
an indentifier has always looked like the transcript of a very fast talker.
Yes, you can make out the words, but just barely. Moreover, the use of
letter case to delineate words prohibits any other use of letter case. It
rules out using all caps for a certain category of identifiers, for example.

There is an easy way to test which convention is more readable. Here is one
of Shakespeare's sonnets rendered in the mixed case format:

FromFairestCreaturesWeDesireIncrease,
ThatTherebyBeautysRoseMightNeverDie,
ButAsTheRiperShouldByTimeDecease,
HisTenderHeirMightBearHisMemory:
ButThouContractedToThineOwnBrightEyes,
FeedstThyLightsFlameWithSelfSubstantialFuel,
MakingAFamineWhereAbundanceLies,
ThySelfThyFoeToThySweetSelfTooCruel:
ThouThatArtNowTheWorldsFreshOrnament,
AndOnlyHeraldToTheGaudySpring,
WithinThineOwnBudBuriestThyContent,
AndTenderChurlMakstWasteInNiggarding:
PityTheWorldOrElseThisGluttonBe,
ToEatTheWorldsDueByTheGraveAndThee

It may be a matter of taste, but I certainly found the original sonnet to be
more readable and more beautiful.
But produces more compilation errors.
Hence the mixed case format must be better for programming.
--
"Hope is replaced by fear and dreams by survival, most of us get by."
Stuart Adamson 1958-2001

Mad Hamish
Hamish Laws
(e-mail address removed)
 
G

Gerry Quinn

I've tried just about every combination over the years. At one
point it was underscores in function names, not in data names.
OOP added enough other basic types of things it got hard to have
a style for each. Currently, I use lower_case_with_underscores
for local names and CamelCaseMode for functions/methods and
for global data.

I use:

ClassName // need not start with C
FunctionName()
m_MemberVariable // misc. variable
m_pPointerVariable // common typed variable
localVariable
pLocalPointer
SOME_CONSTANT

I guess I could use underscore more if I wanted. Don't like typing it
much, though.

I think what I dislike about underscores is related to what some people
like about them: they look like spaces. That interferes with my ability
to break up a statement into individual identifiers.

When someone posts code with lots of underscores, I find it hard to
read.

Gerry Quinn
 
R

Richard Heathfield

[Uncomfortable with crosspost, but not sure which groups to trim]

Jack said:
Interestingly I see a lot of programmers who prefer CamelMode for
function names, yet prefer under_scores in variable names. In every
single case where I have checked, the programmer has done at least
some coding for Windows and its Pascal, BASIC, etc., API. And in
every single case they claim that is not where their style came from.
Go figure.

Add another one to your tally. I have written a fair few Windows programs.
But /before/ that, I had already invented MixedCase for myself. I was quite
pleased, actually, to discover that the Windows API people had copied my
style. :)
 
R

Robert I. Eachus

Richard said:
[Uncomfortable with crosspost, but not sure which groups to trim]

I trimmed comp.lang.ada. I don't know about the other languages, but in
Ada names like Ada.Text_IO.Integer_IO are a part of the standard.
Mixing that with any other style looks uglier than any unmixed style.
So it is sort of forced on anyone who cares, and most are happy with it.

--
Robert I. Eachus

"Quality is the Buddha. Quality is scientific reality. Quality is the
goal of Art. It remains to work these concepts into a practical,
down-to-earth context, and for this there is nothing more practical or
down-to-earth than what I have been talking about all along...the repair
of an old motorcycle." -- from Zen and the Art of Motorcycle
Maintenance by Robert Pirsig
 
I

Ian Woods

[Uncomfortable with crosspost, but not sure which groups to trim]

Jack said:
Interestingly I see a lot of programmers who prefer CamelMode for
function names, yet prefer under_scores in variable names. In every
single case where I have checked, the programmer has done at least
some coding for Windows and its Pascal, BASIC, etc., API. And in
every single case they claim that is not where their style came from.
Go figure.

Add another one to your tally. I have written a fair few Windows
programs. But /before/ that, I had already invented MixedCase for
myself. I was quite pleased, actually, to discover that the Windows
API people had copied my style. :)

Indeed! It's not exactly a huge leap of imagination to go from

somename

to realise that

someName

or

SomeName

is generally easier to spot.

I'm just wondering when someone will pull out a patent on such an obvious
thing.

Ian Woods
 
M

Martin Dowie

Mad Hamish said:
But produces more compilation errors.
Hence the mixed case format must be better for programming.

Are you arguing that more compilation errors are a godd thing or a bad
thing?...

"Hope is replaced by fear and dreams by survival, most of us get by."
Stuart Adamson 1958-2001

"Nice quote" says Dunfermline resident.
 
J

James Dow Allen

On 25 Sep 2003 21:32:40 -0700, (e-mail address removed) (Andy Glew) wrote in
comp.lang.c++:

In the discussion I haven't yet seen the *correct* answer. :)

CamelMode, camel_mode, etc. are all quite *readable*; when using long
names the important thing is to make them *writable*, i.e.
easy to remember.

Consistency is therefore the important thing. If you abbreviate words,
abbreviate them as the first 4 (or whatever) letters, consistently.

(I usually rewind a file with "lseek(fd, 0L, 0)" because I can't
remember if 0 is SEEKSET or SEEK_SET.)

James
 
G

Georg Bauhaus

: Since identifiers are generally phrases (nown phrases
: for objects, verb phrases for procedures) and phrases often consist
: of more than one word, I find the use of underscores to be quite
: natural.

But we should, I think, consider non-phrases or almost-non-phrases
being used as identifiers, and "juxtapositions" of identifiers. The
isolated identifiers might be shorter and thus more easily broken
into parts during the "reading process".

theFools(42);

the_fools (42);

the_Fools(42);

The_Fools (42);

....

y := doYouMind.ifI();

y := do_you_mind.if_i ();

y := do_You_Mind.if_I();

y := Do_You_Mind.If_I ();


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

So in context, your "Shakespearean" argument might still apply,
even if short identifiers are readable in dense mixed case?

: There is an easy way to test which convention is more readable. Here
: is one of Shakespeare's sonnets rendered in the mixed case format:

: FromFairestCreaturesWeDesireIncrease,


Also, looking closely at letters, fonts certainly do matter.
In a string such as "glubf()" it might or might not be easy
to distinguish the two characters 'f' and '('. It depends on
how ink would be spread, or on how pixels would appear on some
display screen. You can see this comparing foo(a) and oof(a),
using different fonts for the letters and symbols.

Georg
 
M

Mike Bandor

I was once told by a TRW employee that on one particular project they had a
coding standard that used underscores in lieu of running the names together.
One of their "measures" of readability was to take copy of the code, remove
the underscores, and run it through a spell checker. If it made it through
the spell checker, it was deemed "readable".


--
Mike Bandor, Software Engineer, BS-CS/SE
Ada83, Ada95, C++, Delphi, JavaScript, WinHelp, PL/SQL, SQL, JOVIAL, MASM,
Java, HTML
Creator of MEGATERMS, Military Terms & Acronyms
http://home.satx.rr.com/bandor/megaterm/megaterm.htm
 
P

Peter Ammon

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

Specifically, are names formed with
underscores more or less readable
than names formed with MixedCase
StudlyCaps camelCase?

[...]

Since camelCase and MixedCase seem to be getting routed by underscore
proponents, here's one example of where something in mixed case is
significantly more readable. It's an excerpt from a bison grammar file
I'm working on.

classmethod :
access_specifier method_type_specifier method_return_type_specifier
method_declaration method_body

In the body, I reference things like $4, which (for those who don't
know) refers to the fourth symbol in that space delimited list above.
Can you quickly count which is the fourth? I can't, since spaces look
similar to underscores.

Compare to

classmethod :
accessSpecifier methodTypeSpecifier methodReturnTypeSpecifier
methodDeclaration methodBody

The second is much more readable IMO. The effect is even more dramatic
without Usenet's line wrapping.

-Peter
 
P

Programmer Dude

Peter said:
classmethod :
access_specifier method_type_specifier method_return_type_specifier
method_declaration method_body

Can you quickly count which is the fourth?
Compare to

classmethod :
accessSpecifier methodTypeSpecifier methodReturnTypeSpecifier
methodDeclaration methodBody

Compare to

classmethod :
access_specifier
method_type_specifier
method_return_type_specifier
method_declaration
method_body

Or my preference if the tool allows

classmethod :
access-specifier
method-type-specifier
method-return-type-specifier
method-declaration
method-body

(In proportional fonts, hyphens are usually skinnier than
underscores and (to my eye) make the text more readable.
It's not as noticable with monospace fonts, but I think the
lower example looks better (read: more readable :).)
 
L

Leif Roar Moldskred

Mike Bandor said:
I was once told by a TRW employee that on one particular project they had a
coding standard that used underscores in lieu of running the names together.
One of their "measures" of readability was to take copy of the code, remove
the underscores, and run it through a spell checker. If it made it through
the spell checker, it was deemed "readable".

This touches on one of my pet annoyances with development tools today:
no way to easily spell-check your code. In my opinion, a development
environment should at the very _least_ let you easily spell-check all
the text in comments, and preferably the individual words in variable
and function names (whether the words are separated by mixed case,
hyphens or underscores.)

Unfortunately, nobody else seems to mind. *sighs* Oh well,
spell-checkers are overrated anyway.
 
W

William

Leif Roar Moldskred said:
This touches on one of my pet annoyances with development tools today:
no way to easily spell-check your code. In my opinion, a development
environment should at the very _least_ let you easily spell-check all
the text in comments, and preferably the individual words in variable
and function names (whether the words are separated by mixed case,
hyphens or underscores.)

I've used a few things that did have spell checking. (One had a spell
check button on certain text fields in its forms, kinda neat.) My favorite
text and source editor, Ultraedit, has a pretty good spell checker and it
can be expanded to handle reserved words. I don't think it handles
mixed case (or case at all) though. I've never used it except to check
comments or display text. -Wm
 
W

William

William said:
I've used a few things that did have spell checking. (One had a spell
check button on certain text fields in its forms, kinda neat.) My favorite
text and source editor, Ultraedit, has a pretty good spell checker and it
can be expanded to handle reserved words. I don't think it handles
mixed case (or case at all) though. I've never used it except to check
comments or display text. -Wm

Talking to myself here... I occurred to me that its syntax highlighting
makes spell checking reserved words less necessary - and the syntax
highlighting can deal with case. -Wm
 
L

Leif Roar Moldskred

William said:
Talking to myself here... I occurred to me that its syntax highlighting
makes spell checking reserved words less necessary - and the syntax
highlighting can deal with case. -Wm

What I want though, is a spell-checker that, for instance for java,
will spot the errors such as this

// Number of misspelled words fuond so far
int noErorsInTetx = 0;

I want to spell-check this such that I get notified both on "fuond"
for "found", "Erors" for "Errors" and "Tetx" for "Text". They are all,
after all, words in natural language, and it should be possible to
spell-check them automatically.
 
J

Jim Rogers

William said:
Talking to myself here... I occurred to me that its syntax highlighting
makes spell checking reserved words less necessary - and the syntax
highlighting can deal with case. -Wm

Even more to the point -- any compiler should be
able to properly recognize reserved words.
Why use another tool to check what the compiler will also check?

Jim Rogers
 
K

Kevin Morenski

// Number of misspelled words fuond so far
int noErorsInTetx = 0;

I want to spell-check this such that I get notified both on "fuond"
for "found", "Erors" for "Errors" and "Tetx" for "Text". They are all,
after all, words in natural language, and it should be possible to
spell-check them automatically.

Let's say you had a variable named "tHTa," for example. With respect to
your concept, this would be a misspelling of the word "that." Now, a lot of
programmers--myself included--use letters to represent certain things in
variable names. tHTa could mean "type HTa" or anything else a programmer
could think of. How could a program possibly differentiate between
conventions in the naming of variables?

It's much simpler to check the spelling of comments...programmers have
developed so many conventions for making their lives easier; a spell checker
on variable names just adds one more problem to overcome.

kevin
 
M

Mike Wahler

Leif Roar Moldskred said:
What I want though, is a spell-checker that, for instance for java,
will spot the errors such as this

// Number of misspelled words fuond so far
int noErorsInTetx = 0;

I want to spell-check this such that I get notified both on "fuond"
for "found",

Agree so far.
"Erors" for "Errors" and "Tetx" for "Text". They are all,
after all, words in natural language, and it should be possible to
spell-check them automatically.

But Java (or C++ or whatever) is *not* a "natural language",
afaik they all allow any spelling whatever (of course with
some necessary exceptions and limitations) of identifiers.

I often create "abbreviated" identifers which
save typing while still retaining enough meaning,
e.g.

struct Emp
{
string FName;
string LName;
/* etc */
};

I wouldn't want a spell checker to flag those
identifers, and I certainly don't want to be
bothered with needing to always add such invented
words to a checker's dictionary.

-Mike
 
P

Peter Ammon

Programmer said:
Peter Ammon wrote:




Compare to

classmethod :
access_specifier
method_type_specifier
method_return_type_specifier
method_declaration
method_body

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(); }

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(); }

This looks like it's getting hard to read.
Or my preference if the tool allows

classmethod :
access-specifier
method-type-specifier
method-return-type-specifier
method-declaration
method-body

(In proportional fonts, hyphens are usually skinnier than
underscores and (to my eye) make the text more readable.
It's not as noticable with monospace fonts, but I think the
lower example looks better (read: more readable :).)

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.

-Peter
 
W

Wes Groleau

Peter said:
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.

Does Dylan prevent having variables named Max,
Max-Iterations, & Iterations in the same scope?
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top