472,976 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Opinions about underscores in names


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. I have even
written a C++ book in which all programs are written
with natural names. More information and free pages
of the book can be found at
http://www.naturalprogramming.com/cppbook.html

I'm planning to produce similar books with the C# and
Java programming languages, but there is one thing
related to naming of which I would like to hear opinions.

In the C++ world it is common to separate the words
of a long name with underscore characters. These kinds
of names look like

integer_from_keyboard
find_largest_number_in_array
character_index
file_to_be_copied

In the Java and C# worlds, it is common to use capitalization
to mark the beginning of a new word in a name. If the above
names would appear in a Java program, they would look like

integerFromKeyboard
findLargestNumberInArray
characterIndex
fileToBeCopied

The naming style in which the first word is not capitalized
and the following words are capitalized is called camel casing,
obviously because the names look a little bit like camels.

I have been thinking which names, the names with underscores or
the camel-cased names, are more readable and natural. I have
tried programming with both styles, and my own conclusion is that
the C++ -style names with underscores are more readable. It is
easier to read them because the words are clearly separated
with underscores. The underscores leave empty space between words,
and that is what we are accustomed to when reading "natural
texts". OrDoYouThinkThatThisSentenceIsReadable?

I would like to hear your opinions about this matter. So my
question is: Which way to mark the beginning of a new word
in a long name makes the names most readable?

Please note that I'm not asking opinions about the idea of
natural naming. I'm asking opinions about how words should
be separated in a long natural name. If you want to know
why I'm too much interested in names in programs, please
read the freely available epilogue of the above-mentioned
book.
--
Mr. (Dr.) Kari Laitinen
Oulu Institute of Technology, Finland
http://www.naturalprogramming.com/
Jul 19 '05 #1
2 3143
"Kari Laitinen" wrote on 13/11/2003:
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. I have even
written a C++ book in which all programs are written
with natural names. More information and free pages
of the book can be found at
http://www.naturalprogramming.com/cppbook.html

I'm planning to produce similar books with the C# and
Java programming languages, but there is one thing
related to naming of which I would like to hear opinions.

In the C++ world it is common to separate the words
of a long name with underscore characters. These kinds
of names look like

integer_from_keyboard
find_largest_number_in_array
character_index
file_to_be_copied

In the Java and C# worlds, it is common to use capitalization
to mark the beginning of a new word in a name. If the above
names would appear in a Java program, they would look like

integerFromKeyboard
findLargestNumberInArray
characterIndex
fileToBeCopied

The naming style in which the first word is not capitalized
and the following words are capitalized is called camel casing,
obviously because the names look a little bit like camels.

I have been thinking which names, the names with underscores or
the camel-cased names, are more readable and natural. I have
tried programming with both styles, and my own conclusion is that
the C++ -style names with underscores are more readable. It is
easier to read them because the words are clearly separated
with underscores. The underscores leave empty space between words, and that is what we are accustomed to when reading "natural
texts". OrDoYouThinkThatThisSentenceIsReadable?

I would like to hear your opinions about this matter. So my
question is: Which way to mark the beginning of a new word
in a long name makes the names most readable?

Please note that I'm not asking opinions about the idea of
natural naming. I'm asking opinions about how words should
be separated in a long natural name. If you want to know
why I'm too much interested in names in programs, please
read the freely available epilogue of the above-mentioned
book.


This subject has been discussed quite extensively in the
comp.programming newsgroup. The title of the thread there is "ISO
Studies of underscores vs MixedCase in Ada or C++". It was started
some time ago, you may need to use an archive (such as Google groups)
to read it all. I lost track quite some time ago, so I don't know the
current direction of the thread.

There is also an earlier thread in this group called
"thisIsAMemberFunctionName vs this_is_a_member_function_name" on the
same subject.

Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.uk (remove [no-spam] to reply)
Jul 19 '05 #2

Hi Kari Laitinen,

"Kari Laitinen" <ka***********@oamk.fi> schrieb im Newsbeitrag
news:3F***************@oamk.fi...
I would like to hear your opinions about this matter. So my
question is: Which way to mark the beginning of a new word
in a long name makes the names most readable?


In my opinion, it depends on what type of code you're working on.

If you don't want to spend a lot of time typing, it might be more convenient
using shorter names, with or without capitalization.

Readability matters foremost when many people are working on the same piece
of code.

You might also want to have a look at other naming schemes, like that
endorsed by Microsoft, which recommends class data members beginning with
"m_" (for member), followed by a type identifier, followed by a capitalized
name. For example, "m_iCurrentMileage" would denote an integer named
"CurrentMileage" as a class member.

Readability might also depend on the issue whether you capitalize the names
of member functions. Like "ParkCar" might be more readable in expressions
like "myCar.ParkCar()" than "my_car.park_car()", especially when you have a
lot of dereferentiations, as in
'blue_window->entry_field["account_number"]->set_foreground_color(
public_color_table->get_color_value_for_color( "marine_blue" ) );' instead
of 'blueWindow->entryField["account#"]->setFgCol(
pubColTab->GetColor("marineblue") );'

If in complex expressions, program lines become too long, so that they have
to be split over several lines, the readability of the code might suffer
more than when using shorter, capitalized names.

If I don't have to follow specific guidelines, I always use the type of
notation that seems more convenient to me and the task at hand.

I hope that helps.

Regards,
Ekkehard Morgenstern.


Jul 19 '05 #3

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

Similar topics

31
by: Chris S. | last post by:
Is there a purpose for using trailing and leading double underscores for built-in method names? My impression was that underscores are supposed to imply some sort of pseudo-privatization, but would...
84
by: Andy Glew | last post by:
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...
22
by: BRIAN VICKERY | last post by:
I've heard that some compilers reserve the '_' starting a symbol for system variables/symbols. I can not find this documented anywhere (so far). I've used an '_' at the end of member variables...
46
by: James Harris | last post by:
Before I embark on a new long-term project I'd appreciate your advice on how to split up long names. I would like to keep the standards for command names the same as that for variable names....
10
by: Peter Kirk | last post by:
Hi I am looking at some C# code, and can see in some of the classes there are instance variables whose names start with an underscore, for example: private string _projectId; Is there a...
187
by: Lasse Espeholt | last post by:
Hi... I am relativ new to the impressive and powerfull C language, but i thinks it is obsolete... The idea with header/source files where methods can clash into eachother i don't like... Look...
20
by: benhoyt | last post by:
Hi guys, I've been using Python for some time now, and am very impressed with its lack of red tape and its clean syntax -- both probably due to the BDFL's ability to know when to say "no". ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.