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/