C++ Variable Names Poll

Do you use underscores or capitalization at each new word in a variabl

Page 1 of 1

13 Replies - 4075 Views - Last Post: 02 June 2009 - 11:12 PM

Poll: Underscores or Recapitalization? (27 member(s) have cast votes)

Underscores or Recapitalization?

  1. Underscores (5 votes [18.52%])

    Percentage of vote: 18.52%

  2. Recapitalization (22 votes [81.48%])

    Percentage of vote: 81.48%

Vote Guests cannot vote

#1 xiii1408   User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 30-May 09

C++ Variable Names Poll

Posted 01 June 2009 - 09:32 AM

When you declare variables, do you use underscores or recapitalization (see below).

int my_variable; // Do you use this?
int myVariable // or this?

Is This A Good Question/Topic? 0
  • +

Replies To: C++ Variable Names Poll

#2 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,235
  • Joined: 14-September 07

Re: C++ Variable Names Poll

Posted 01 June 2009 - 09:37 AM

recapitalization. I hate underscores, especially in the beginning of a variable.
Was This Post Helpful? 0
  • +
  • -

#3 deery5000   User is offline

  • D.I.C Lover

Reputation: 87
  • View blog
  • Posts: 1,097
  • Joined: 09-May 09

Re: C++ Variable Names Poll

Posted 01 June 2009 - 09:46 AM

For me :)

int myVariable

my reason is it looks better plus i hate having to hold shift + - :P
Was This Post Helpful? 0
  • +
  • -

#4 stayscrisp   User is offline

  • フカユ
  • member icon

Reputation: 1040
  • View blog
  • Posts: 4,325
  • Joined: 14-February 08

Re: C++ Variable Names Poll

Posted 01 June 2009 - 10:09 AM

Definitely recapitalization.
Was This Post Helpful? 0
  • +
  • -

#5 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7361
  • View blog
  • Posts: 15,285
  • Joined: 16-October 07

Re: C++ Variable Names Poll

Posted 01 June 2009 - 10:11 AM

Recapitalization? That a new one on me. I like the term CamelCase, because it's both descriptive and a little whimsical. Although NerdCaps is growing on me. WikiPedia has an entire entry on the things. Recapitalization is not mentioned.

I prefer CamelCase to underscores. Underscores are required if you have a non case sensitive, or mono case system. Thankfully, those are more rare than they used to be.
Was This Post Helpful? 0
  • +
  • -

#6 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1586
  • View blog
  • Posts: 8,405
  • Joined: 07-September 06

Re: C++ Variable Names Poll

Posted 01 June 2009 - 10:11 AM

reCap all the way.
Was This Post Helpful? 0
  • +
  • -

#7 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: C++ Variable Names Poll

Posted 01 June 2009 - 10:47 AM

For variable names and function names I use camel case.

For macros I always use UPPERCASE -- and here I use underscores.

For constants/Enum elements I tend to use Upper case as well.

For Classes/structs/enums/typedefs I capitalize the first letter and then use camel case.

I don't use Hungarian notation but sometimes I do get Hungarian notation-ish - I will often prefix integer with i and longs with l and pointers with p (or ptr). I often extend this to a naming convention consistent with the current app.
Was This Post Helpful? 0
  • +
  • -

#8 Pwn   User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: C++ Variable Names Poll

Posted 01 June 2009 - 05:35 PM

I use underscores for one reason...that's what we were taught in database class. I was on the way to using a standardized convention until then. After that, I figured, to make things simpler for my brain, to standardize across it all, and since so much of programming has to do with databases, it just made sense to adopt that standard (is it standard?) into my programming.
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,140
  • Joined: 10-May 07

Re: C++ Variable Names Poll

Posted 01 June 2009 - 09:12 PM

Underscores. Caps in the middle of variable names brings back haunting memories of QBasic auto case correction.

*shudders*

As well, from a technical perspective, it eliminates keywords confusion & possible keyword usage. Does caps do that as well? Are keywords case sensitive in C/C++? I believe that they are. But there is no WAY that an underscore can be confused with a keyword :P
Was This Post Helpful? 0
  • +
  • -

#10 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: C++ Variable Names Poll

Posted 02 June 2009 - 03:24 AM

There are some fairly well established conventions on this that you might as well follow as most shops you join will require you to follow the internal style and the most common style is the one they are most likely going to be using.

There are even standard names for the styles which is a kinda big hint as to the commonality of their usage.

Variables / Methods / Functions = camelCase (note leading lowercase on camel)
e.g. -> theNumberOfSheep / shipOneSheepToMarket()

Classes = CamelCase (note leading Capital on Camel)
e.g. -> Sheep / Ship

Constants / Macros = ALL_CAPS (with underscores)
e.g. -> MAX_SHEEP_IN_PEN


Here's some reading to research on:
http://www.possibili...ngStandard.html
http://geosoft.no/de...le.html#General
http://www.flipcode....ode_Style.shtml
http://www.alma.nrao.../2001-08-10.pdf
http://www.yolinux.c....html#CAMELCASE

Now the fact that this is the most commonly followed style doesn't mean it is universal (have a look at variations in the lin ks provided) but I do think I am right in saying these are the most common - evidence to the contrary anyone?
Was This Post Helpful? 0
  • +
  • -

#11 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7361
  • View blog
  • Posts: 15,285
  • Joined: 16-October 07

Re: C++ Variable Names Poll

Posted 02 June 2009 - 04:28 AM

View Postjanotte, on 2 Jun, 2009 - 04:24 AM, said:

Variables / Methods / Functions = camelCase (note leading lowercase on camel)
e.g. -> theNumberOfSheep / shipOneSheepToMarket()

Classes = CamelCase (note leading Capital on Camel)
e.g. -> Sheep / Ship

Constants / Macros = ALL_CAPS (with underscores)
e.g. -> MAX_SHEEP_IN_PEN


I tend to follow these in C and Java. Alas, I have been corrupted by Microsoft to some extent and use the C# standard, which often leaks out into other languages. Basically, all CamelCase, all the time, with only variable names starting in lower case, everything else starting in upper case. It's actually pretty easy to follow and a little similar than the above.
Was This Post Helpful? 0
  • +
  • -

#12 SixOfEleven   User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: C++ Variable Names Poll

Posted 02 June 2009 - 06:29 AM

I use a little bit of custom reCaping.

For public identifiers:

public int MyNumber;
public void MyFunction()

For local variables:

int myNumber;

For private I use:

private int myNumber;
private void myFunction()

*edit*
For large projects that I did as part of a team we used to use Hungarian notation. Haven't really seen that used in a while though.

This post has been edited by SixOfEleven: 02 June 2009 - 06:31 AM

Was This Post Helpful? 0
  • +
  • -

#13 xiii1408   User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 30-May 09

Re: C++ Variable Names Poll

Posted 02 June 2009 - 08:04 AM

The ANSI/ISO C++ standard doesn't say anything about CamelCase vs. Underscores, so it's mostly a matter of choice, but it uses Underscores in code examples (according to C++ Black Book).
Was This Post Helpful? 0
  • +
  • -

#14 Kanvus   User is offline

  • D.I.C Regular
  • member icon

Reputation: 42
  • View blog
  • Posts: 452
  • Joined: 19-February 09

Re: C++ Variable Names Poll

Posted 02 June 2009 - 11:12 PM

Apple made camelcase look too good to pass up. Guilty @[email protected] ... iConform!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1