A "Naming Conventions" question

This is a discussion on A "Naming Conventions" question within the C++ Programming forums, part of the General Programming Boards category; Hi, there are some conventions in C++ language in naming the variables, objects, functions, etc... . And for example the ...

  1. #1
    Beginning game programmer Petike's Avatar
    Join Date
    Jan 2008
    Posts
    64

    A "Naming Conventions" question

    Hi,
    there are some conventions in C++ language in naming the variables, objects, functions, etc... . And for example the convention for naming classes are: the 1st letter should be UPPERCASE and there shouldn't be any "_"-underscore character to divide letters but there should be each new word written with UPPERCASE letter: For example: "SimpleClass" or "MyNewClass".
    Or one example for writing functions: "simpleFunction()", "myFunction()".

    AND THE QUESTION IS:
    Why for example the class from <string> library is written as "string" (or "basic_string<char>") or some variables are written as "out_of_scope". So that they are written WITH UNDERSCORE and classes WITH SMALL LETTERS?

    Thanks.

    Petike

  2. #2

    Join Date
    Apr 2008
    Location
    USA
    Posts
    76
    Conventionally, classes in the C++ standard library use lower-case letters and underscores to make it more clear that they are part of the standard, and not just a random user-defined class.

  3. #3
    Beginning game programmer Petike's Avatar
    Join Date
    Jan 2008
    Posts
    64
    Thanks

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    There are no naming conventions in C++, as such. Different entities (persons, companies, or even programming cultures) have conventions.

    So, for example, the CamelCase convention you describe for classes is used by many companies, projects and cultures (e.g. QT, with a Q prefix, wxWidgets, with a wx prefix, or the Java culture), but it is not inherent to C++.

    C++'s standard library is named using the K&R C culture, where mixed case is non-existent and upper case is reserved for macros and constants (with the very atypical exception of the FILE type). Therefore, it's string and runtime_error and copy_backwards. Note that C++, having come into existence in a time where memory was no longer measured in two-digit kilobyte numbers and where compilers thus allowed names longer than perhaps 10 characters, stopped using abbreviations for names and thus has no new names like atoi ("asciiz to integer"), strstr ("find string in string") or execvp ("load executable with a pointer to a variable number of arguments").
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Just be consistent with whatever you choose. And if you're editing someone else's code, follow their conventions.

    Of course, when you're writing anything non-trivial, you'll inevitably get convention clashes in libraries. CamelCase, snake_case, and if you're unlucky enough to be doing Windows programming, the scourge of the programming world, convHungarianNotation.

  6. #6
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Quote Originally Posted by medievalelks View Post
    Just be consistent with whatever you choose. And if you're editing someone else's code, follow their conventions.

    Of course, when you're writing anything non-trivial, you'll inevitably get convention clashes in libraries. CamelCase, snake_case, and if you're unlucky enough to be doing Windows programming, the scourge of the programming world, convHungarianNotation.
    So true...
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21