Opinions about underscores in names

Discussion in 'C++' started by Kari Laitinen, Nov 13, 2003.

  1. 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/
    Kari Laitinen, Nov 13, 2003
    #1
    1. Advertising

  2. "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)
    Michael Winter, Nov 13, 2003
    #2
    1. Advertising

  3. Hi Kari Laitinen,

    "Kari Laitinen" <> schrieb im Newsbeitrag
    news:...
    > 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.
    Ekkehard Morgenstern, Nov 13, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laura
    Replies:
    1
    Views:
    402
    Laura
    Jun 3, 2004
  2. J. Hall
    Replies:
    4
    Views:
    1,116
    J. Hall
    Jun 3, 2004
  3. Andy Glew
    Replies:
    84
    Views:
    1,862
    Dave Vandervies
    Oct 28, 2003
  4. BRIAN VICKERY

    underscores in class member names

    BRIAN VICKERY, Jan 30, 2004, in forum: C++
    Replies:
    22
    Views:
    728
    Rolf Magnus
    Feb 1, 2004
  5. James Harris
    Replies:
    46
    Views:
    1,003
    Ronald Landheer-Cieslak
    Jul 23, 2004
Loading...

Share This Page