471,613 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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

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?

....and similarly, any measurements
of programmer productivity, bug rate,
etc.; although IMHO readability matters
most.
* Religion - NOT?!

I understand that this is a religious issue
for many programmers, an issue of programming style.
I am not interested in a religious war.
I obviously have my own opinion, but I am
open to scientific evidence.
* Ada Studies?

I thought that I had seen studies like
this in some of the early design documents
for Ada, but I have not been able to find
such references on the web. Which is not
entirely surprising, since Ada was designed
prior to the web.

The Ada 83 and 95 Quality Guidelines recommend
underscores to improve readability, but provide
no source justifying this statement.
* What such studies might look like

Simple readability and recall:
- present a test subject with
a list of compound words
formed with underscoresand mixed case
- remove the list, and ask test subject
to write it
- score on accuracy

Program debugging
- present programs that are otherwise identical,
differing only in their use of underscores/MixedCase
to test subject programmers (e.g. a CS class)
- program has a known bug
- ask test subjects to find bug
- score on accuracy locating bug

Cruel TA study:
- Two sections of a CS class
- Enforce programming standards,
underscores vs MixedCase
- Pose a programming problem
- Score according to success
completing assignment

Empirical:
- Given version control databases
of large programs, some written in underscore
style, others in MixedCase
- Total bug rates normalized by LOC, name count, etc.
- OR: count only bugs that can be attributed
(after inspection of checkins) to misnamed variables

For that matter, I would be interested in any surveys
folks may have done that count projects and their
coding standards, possibly weighted
- open source (e.g. sourceforge)
- industrial
- textbooks, weighted by sales
- websites of coding standards, weighted by Google score...
Although this is less convincing than a rigorous study.
* Explanation of Newsgroups Chosen

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
Jul 19 '05
84 5519
>>>>> "Martin" == Martin Dowie <ma**********@btopenworld.com> writes:

: "Matt Gregory" <bl****************@earthlink.net> wrote in message
: news:BPvfb.20445
:: > 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.
::
:: Lisp and Scheme.

: COBOL

Also a few languages, like SNOBOL4, that allow you to have
any string as a variable name,

$'The Shoemaker - page 3' = 'Once upon a time'

ML allows minus {minus} as identifiers, and also ":->" and the like,
though not ":-)".
Georg
Jul 19 '05 #51
"Jakob Bieling" <ne*****@gmy.net> writes:
But it is that kind of word-matching I would personally like to see in
more compilers (specifically C++ compilers).

I do agree with Kevin Morenski (news:3f********@nntp2.nac.net) that a
real spell-checker for source code is not practicable. You said that the
spell-checker would just have to ask you whether to ignore it or how else to
proceed. Have you thought about how annoying 100s or even 1000s of those
messages boxes, asking how to proceed, will be when compiling already
existing source with this spell-checker?


Oh, I wouldn't want it to be part of the compiler, or continiously on. Rather,
I'd just want to be able to run a command in my editor to spell-check the
source-code I'm currently working on - much like I today invoke ispell in
emacs for regular text files.

--
Leif Roar Moldskred
Jul 19 '05 #52
James Dow Allen wrote:
(I usually rewind a file with "lseek(fd, 0L, 0)" because I can't
remember if 0 is SEEKSET or SEEK_SET.)

The best choice for rewinding a stdio file stream is rewind().


Brian Rodenborn
Jul 19 '05 #53
"Leif Roar Moldskred" <rm******@online.no> wrote in message
news:86************@huldreheim.huldreskog.no...
"Jakob Bieling" <ne*****@gmy.net> writes:
But it is that kind of word-matching I would personally like to see in more compilers (specifically C++ compilers).

I do agree with Kevin Morenski (news:3f********@nntp2.nac.net) that a real spell-checker for source code is not practicable. You said that the
spell-checker would just have to ask you whether to ignore it or how else to proceed. Have you thought about how annoying 100s or even 1000s of those
messages boxes, asking how to proceed, will be when compiling already
existing source with this spell-checker?
Oh, I wouldn't want it to be part of the compiler, or continiously on.

Rather, I'd just want to be able to run a command in my editor to spell-check the
source-code I'm currently working on - much like I today invoke ispell in
emacs for regular text files.

Ah, I did not consider this difference even. *g* My point was, checking
my own identifier names for spelling errors based on natural language rules
is a bad idea. Instead, a special code-spell-checker would be great:

a/ 'Created' identifiers are automatically added to the list of known
words (for the current compilation run only)
b/ When an identifier is used, but not found, the spell-checker tries to
find out what I meant (like any spell-checker)
c/ Comments are spell-checked like in any other word processor, except
that identifier names should also be considered

So let us assume we have this (rather useless) piece of C++ code:

1 int main ()
2 {
3 char* pRok = new char;
4 *pork = 'p';
5 delete pRok; // do not forget t delete pRok!
6 }

In line 3, the spell-checker should not question the identifier name and
try to tell me that I meant 'pork' (see a/ above). Instead, it should tell
me in line 4 that I most probably meant 'pRok' and not 'pork' (see b/
above). And last but not least, in line 5, the spell-checker should point
out the missing 'o' (ie. ".. forget to ..") but leave 'pRok' undiagnosed.

regards
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #54
"Default User" <fi********@company.com> wrote in message
news:3F***************@company.com...
The best choice for rewinding a stdio file stream is rewind().


Nah, rewind() makes me think of tapes, and that makes me feel old.
Jul 19 '05 #55
Georg Bauhaus wrote:
>> "Martin" == Martin Dowie <ma**********@btopenworld.com> writes:


: "Matt Gregory" <bl****************@earthlink.net> wrote in message
: news:BPvfb.20445
:: > 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.
::
:: Lisp and Scheme.

: COBOL

Also a few languages, like SNOBOL4, that allow you to have
any string as a variable name,

$'The Shoemaker - page 3' = 'Once upon a time'


You can do the same thing in Perl:

${'The Shoemaker - page 3'} = 'Once upon a time';

And since perl interpolates in double quoted strings you can include any
8 bit value:

${"\xFF\0\t\cV"} = 'Once upon a time';
John
--
use Perl;
program
fulfillment
Jul 19 '05 #56
"Jim Rogers" <ji**************@worldnet.att.net> wrote in message
news:82**************************@posting.google.c om...
"William" <Re***@NewsGroup.Please> wrote in message

news:<ud********************@giganews.com>...
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?


Until we got faster machines, one of our builds could take an hour.
No fun to have the compiler detect a mispelled word 50 minutes in.
(Sure, if everyone did an incremental test build, the problem would
be avoided, but...) -Wm
Jul 19 '05 #57
"Leif Roar Moldskred" <rm******@online.no> wrote in message
news:86************@huldreheim.huldreskog.no...

In the same way that spell-checkers for ordinary text today handles names and other words that are correct, but not in the dictionary: When detecting the unknown word the first time, ask the user what to do with it - whether to
correct it, accept this instance, accept all instances in this document or
add it to your private dictionary. (For a spell-checking of source-code we'd probably also want the option "accept all instances with this case.")


Well, they will if you add the entire label to the dictionary, but none I'm
aware
of will break up words based on mixed-case. Ultraedit will break up words
on underscores - didn't know that until I just tried it I can make it ignore
mixed-case words, but not break them apart. (It does support multiple user
dictionaries, so you could have a dictionary-per-project defining all the
approved labels.) -Wm

Jul 19 '05 #58
On Fri, 03 Oct 2003 15:42:20 -0700, Peter Ammon
<pe*********@rocketmail.com> wrote:
<snip>
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.

COBOL ! Only embedded, though. My compiler accepts -X as minus X with
a warning, but I don't think that's standard.

Also the usual suspects: FORTH allows everything but space (and
controls); and LISP everything but space, parens, period, quote,
backquote, and undoubled slash, if I haven't forgotten anything.

- David.Thompson1 at worldnet.att.net
Jul 19 '05 #59

"Kevin Morenski" <km@nospam.geekcenter.net> schrieb im Newsbeitrag
news:3f********@nntp2.nac.net...
// 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.


An editor which is capable of finding the definition of variables and
highlighting a name already defined/declared might solve that problem. VB
has that feature to a certain degree - if you use mixed case for names of
variables, functions etc. and you type a name already declared in lowercase
the editor will automatically convert it to the form in which it is
declared. If you know, the name is declared and case does not flip you know
you made a typo. IIRC Keil development system for embedded C programming has
a similar feature.

just my $0.02
Robert
Jul 19 '05 #60
an*******@amd.com (Andy Glew) wrote in message news:<2c**************************@posting.google. com>...
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
Jul 19 '05 #61
Peter Ammon wrote:
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(); }


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

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


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

--
|_ CJSonnack <Ch***@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|
Jul 19 '05 #62
> 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

"Georg Bauhaus" <ge***@strudel.futureapps.de> wrote in message
news:86************@strudel.futureapps.de...
Jul 19 '05 #63
"Jacob Sparre Andersen" <sp****@crs4.it> wrote in message
news:3F**************@crs4.it...
Jakob Bieling wrote:
"Leif Roar Moldskred" <rm******@online.no> wrote in message
news:86************@huldreheim.huldreskog.no...
"Jakob Bieling" <ne*****@gmy.net> writes:
Ah, I did not consider this difference even. *g* My point was,

checking my own identifier names for spelling errors based on natural language rules is a bad idea.


Why. They are hopefully spelled correctly. Otherwise you are adding an
unneeded complication to reading and understanding your code.
Instead, a special code-spell-checker would be great:

a/ 'Created' identifiers are automatically added to the list of known words (for the current compilation run only)


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 (news:3f********@nntp2.nac.net)
b/ When an identifier is used, but not found, the spell-checker tries to find out what I meant (like any spell-checker)


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
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #64
"Jakob Bieling" <ne*****@gmy.net> wrote in message
news:bm*************@news.t-online.com...
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
Jul 19 '05 #65
In comp.lang.ada Stephen Baynes. <st************@soton.sc.philips.com> wrote:
: 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
Jul 19 '05 #66
Jakob Bieling wrote:
"Jacob Sparre Andersen" <sp****@crs4.it> wrote in message
news:3F**************@crs4.it...

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,


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
--
There only exist 10 kinds of people: Those who know binary
numbers and those who don't know binary numbers.

Jul 19 '05 #67
"Jacob Sparre Andersen" <sp****@crs4.it> wrote in message
news:3F**************@crs4.it...
Jakob Bieling wrote:
"Jacob Sparre Andersen" <sp****@crs4.it> wrote:
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,

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
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #68
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:2z*****************@newsread4.news.pas.earthl ink.net...
"Jakob Bieling" <ne*****@gmy.net> wrote in message
news:bm*************@news.t-online.com...
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. :-)

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

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #69

"Jakob Bieling" <ne*****@gmy.net> wrote in message
news:bm*************@news.t-online.com...
"Jacob Sparre Andersen" <sp****@crs4.it> wrote in message
news:3F**************@crs4.it...

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".
Jul 19 '05 #70
"Peter Bushell" <DE****************@software-inCAPStegrity.com> wrote:
"Jakob Bieling" <ne*****@gmy.net> wrote:
"Jacob Sparre Andersen" <sp****@crs4.it> wrote: 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.
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
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #71
On Tue, 14 Oct 2003 18:46:59 +0200, "Jakob Bieling" <ne*****@gmy.net>
wrote:
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.

--
Al Balmer
Balmer Consulting
re************************@att.net
Jul 19 '05 #72
"Jakob Bieling" <ne*****@gmy.net> wrote:
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.
Jul 19 '05 #73
"Alan Balmer" <al******@att.net> wrote in message
news:hs********************************@4ax.com...
On Tue, 14 Oct 2003 18:46:59 +0200, "Jakob Bieling" <ne*****@gmy.net>
wrote:
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.

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

regards
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #74
<br*******@yahoo.com> wrote in message
news:h5********************************@4ax.com...
"Jakob Bieling" <ne*****@gmy.net> wrote:
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.
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
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #75
On Wed, 15 Oct 2003 07:34:33 +0200, "Jakob Bieling" <ne*****@gmy.net>
wrote:
"Alan Balmer" <al******@att.net> wrote in message
news:hs********************************@4ax.com.. .
On Tue, 14 Oct 2003 18:46:59 +0200, "Jakob Bieling" <ne*****@gmy.net>
wrote:
> 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.

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

--
Al Balmer
Balmer Consulting
re************************@att.net
Jul 19 '05 #76
"Jakob Bieling" <ne*****@gmy.net> writes:
"Alan Balmer" <al******@att.net> wrote in message
news:hs********************************@4ax.com...
On Tue, 14 Oct 2003 18:46:59 +0200, "Jakob Bieling" <ne*****@gmy.net>
wrote:
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.

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

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
Jul 19 '05 #77
James Dow Allen wrote:
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
--
"Any, sufficiently complicated, experiment is indistinguishable from
magic."

Jul 19 '05 #78
Jakob Bieling wrote:
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
--
"The current state of knowledge can be summarised thus:
In the beginning, there was nothing, which exploded."

Jul 19 '05 #79
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
--
"There are only two types of data:
Data which has been backed up
Data which has not been lost - yet"

Jul 19 '05 #80
Jacob Sparre Andersen wrote:
James Dow Allen wrote:
abbreviate them as the first 4 (or whatever) letters, consistently.

So Bandshift should be abbreviated Band ?

Megahertz should be Mega, not MHz ?

Message should be Mess, not Msg ?
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.


And that list should be designed to include only
a limited number of items, using the abbreviation
that is already widely used in the problem domain.

(If no widely-used abbreviation exists, the item
should not be abbreviated.)

And the following practice is sad, but it does happen
in some places:

Problem: "Abbreviation is not on the approved list."
Solution: "Change the list; we're building TODAY."

--
Wes Groleau

Is it an on-line compliment to call someone a Net Wit ?

Jul 19 '05 #81


"Jacob Sparre Andersen" <sp****@crs4.it> wrote in message
news:3F**************@crs4.it...
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")


To me the length of the name should reflect the size of the scope. A one
letter variable name is fine for the counter in a very short for loop, or a
temporary that is only used for a couple of adjacent statements. But if the
variable is used over many lines a longer more meaningful name is required.
Global variables tend to end up with the longest names as they have to be
used and understood in many more contexts.

Like all rules - there are exceptions. In particular if something is used
very frequently then a shorter name is desirable for convenience and
acceptable as it will be well known and understood. [eg 'stderr']

--
Stephen Baynes CEng MBCS
My views are my own

Jul 19 '05 #82
On Fri, 03 Oct 2003 15:42:20 -0700, Peter Ammon
<pe*********@rocketmail.com> wrote:

[snip]
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.


COBOL does.

Sincerely,

Gene Wirchenko

Jul 19 '05 #83
Gene Wirchenko wrote:
On Fri, 03 Oct 2003 15:42:20 -0700, Peter Ammon
<pe*********@rocketmail.com> wrote:

[snip]

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.

COBOL does.

Sincerely,

Gene Wirchenko


Is there a link to a document on ISO Studies of underscores... ?

Thanks, Oplec.

Jul 19 '05 #84
In article <fk********************************@4ax.com>,
Gene Wirchenko <gw**************@CAPITALSwencomine.com> wrote:
On Fri, 03 Oct 2003 15:42:20 -0700, Peter Ammon
<pe*********@rocketmail.com> wrote:

[snip]
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.


COBOL does.


As does Scheme, along with (if I'm not mistaken) most or all of the
other members of the Lisp family.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Remember we're in a language where a misbehaving human can produce
quite a few kleenex-embedded demons.
--Chris Wolfe in comp.lang.c
Jul 19 '05 #85

This discussion thread is closed

Replies have been disabled for this discussion.

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.