CamelCase or PascalCase

Which is Better?

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 5174 Views - Last Post: 20 June 2010 - 04:26 PM

Poll: Which one do you prefer? (13 member(s) have cast votes)

HMMM...

  1. pascalCase (addressTextBox) (6 votes [46.15%] - View)

    Percentage of vote: 46.15%

  2. CamelCase (AddressTextBox (4 votes [30.77%] - View)

    Percentage of vote: 30.77%

  3. Hungarian (txtAddress) (3 votes [23.08%] - View)

    Percentage of vote: 23.08%

Concerning underscores...

  1. use_them (3 votes [25.00%] - View)

    Percentage of vote: 25.00%

  2. burnThem (9 votes [75.00%] - View)

    Percentage of vote: 75.00%

Vote Guests cannot vote

#1 Vermiculus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 314
  • Joined: 26-February 09

CamelCase or PascalCase

Posted 16 June 2010 - 01:16 PM

Advantages/disadvantages of each? It doesn't make a difference run-time, so it's all readability and preference.

This post has been edited by Vermiculus: 17 June 2010 - 05:47 AM

Is This A Good Question/Topic? 0
  • +

Replies To: CamelCase or PascalCase

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: CamelCase or PascalCase

Posted 16 June 2010 - 01:19 PM

In my opinion it's purely preference and readability. I've worked for places that had a coding standard of only camel case and some that only allowed pascal. It makes no difference as far as performance. I will say that people need to pick one and stick with it. It sucks to look through someone's code where they mix and match
Was This Post Helpful? 1
  • +
  • -

#3 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,137
  • Joined: 14-September 07

Re: CamelCase or PascalCase

Posted 16 June 2010 - 01:20 PM

Not sure you have your definitions right. Camel-case can have an initial lower case letter as well.


I prefer:
Class names: uppercase + camel case
functions: lower case+ camel case
Was This Post Helpful? 0
  • +
  • -

#4 xclite  Icon User is online

  • LIKE A BOSS
  • member icon


Reputation: 877
  • View blog
  • Posts: 3,122
  • Joined: 12-May 09

Re: CamelCase or PascalCase

Posted 16 June 2010 - 01:53 PM

I used to use CamelCase exclusively, but then I took a systems course and I find myself using underscores to separate words rather than case.
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: CamelCase or PascalCase

Posted 16 June 2010 - 01:56 PM

Egads, I hate underscores.

Well not 100% true, at times I catch myself using them when writing in MSSQL.

For code though I prefer camel casing personally, it's just easier for me to read and look at.
Was This Post Helpful? 0
  • +
  • -

#6 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,137
  • Joined: 14-September 07

Re: CamelCase or PascalCase

Posted 16 June 2010 - 02:03 PM

The only thing worse then underscores is Hungarian notation. Woof.
Was This Post Helpful? 0
  • +
  • -

#7 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1907
  • View blog
  • Posts: 3,953
  • Joined: 11-December 07

Re: CamelCase or PascalCase

Posted 16 June 2010 - 04:56 PM

lol. I only use underscores when using hungarian notation. And when used properly, Hungarian notation makes fiddly mistakes jump out!

double currentTime_s = 130;
double currentTime_min = currentTime_s / 60.0;

double totalTime_s = endTime_min - startTime_s; // spot this error a mile away ;)/>

Was This Post Helpful? 0
  • +
  • -

#8 nooblet  Icon User is offline

  • D.I.C Addict

Reputation: 120
  • View blog
  • Posts: 541
  • Joined: 12-March 10

Re: CamelCase or PascalCase

Posted 16 June 2010 - 05:44 PM

As others have noted, it's all personal preference. I tend to use camelCase more.
Was This Post Helpful? 0
  • +
  • -

#9 Vestah  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 86
  • Joined: 15-October 09

Re: CamelCase or PascalCase

Posted 17 June 2010 - 02:12 AM

Is it just me or is there a problem with the poll?
camelCase starts as KYA said with a lower case letter.
PascalCase starts with an upper case letter, so the poll should have looked like:

camelCase: addressTextBox
PascalCase: AddressTextBox
Hungarian: txtAddress (Not sure about this)
Was This Post Helpful? 0
  • +
  • -

#10 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1907
  • View blog
  • Posts: 3,953
  • Joined: 11-December 07

Re: CamelCase or PascalCase

Posted 17 June 2010 - 03:13 AM

Quote

Hungarian: txtAddress (Not sure about this)


This is a common misconception and it gives Hungarian notation a bad name. Something like this:

String strAddress = new String("10 Leafy St");


Here the type (String) tells you it is a string or text. Putting that information in the variable name as well is just clutter.

Hungarian notation is useful for keeping track of units or relative offsets. Is that mouse coordinate relative to the screen or the window?
Was This Post Helpful? 0
  • +
  • -

#11 nooblet  Icon User is offline

  • D.I.C Addict

Reputation: 120
  • View blog
  • Posts: 541
  • Joined: 12-March 10

Re: CamelCase or PascalCase

Posted 17 June 2010 - 03:14 AM

View PostVestah, on 17 June 2010 - 01:12 AM, said:

Is it just me or is there a problem with the poll?
camelCase starts as KYA said with a lower case letter.
PascalCase starts with an upper case letter, so the poll should have looked like:

camelCase: addressTextBox
PascalCase: AddressTextBox
Hungarian: txtAddress (Not sure about this)


Yeah the OP got it wrong which is why I didn't vote and just replied with correct casing lol
Was This Post Helpful? 0
  • +
  • -

#12 Vermiculus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 314
  • Joined: 26-February 09

Re: CamelCase or PascalCase

Posted 17 June 2010 - 05:53 AM

View PostVestah, on 17 June 2010 - 03:12 AM, said:

Is it just me or is there a problem with the poll?
camelCase starts as KYA said with a lower case letter.
PascalCase starts with an upper case letter, so the poll should have looked like:

camelCase: addressTextBox
PascalCase: AddressTextBox
Hungarian: txtAddress (Not sure about this)


Yes, there was a problem with the poll. I was reading a little article-type-thing about this earlier yesterday, and didn't do much further research on it. but Wikipedia did confirm the CamelCase starts every word with a capital (if it's a class/struct/etc) and starts only the first word with a lower (if it's a parameter/variable/etc). So it seems that Pascal Case (or Pascal style as Wikipedia calls it) is only the subset of CamelCase where the first letter is not capitalized.

Hungarian notation is the one with the short abbr. at the beginning (txtAddress). My fault; I have revised the poll. Also added a question concerning underscores. I say burnThem.

http://en.wikipedia....ming_convention
http://en.wikipedia....garian_notation
Was This Post Helpful? 0
  • +
  • -

#13 xclite  Icon User is online

  • LIKE A BOSS
  • member icon


Reputation: 877
  • View blog
  • Posts: 3,122
  • Joined: 12-May 09

Re: CamelCase or PascalCase

Posted 17 June 2010 - 06:22 AM

I used to hate the underscores, now they don't bother me. Basically I just try to avoid mixing naming styles within a system these days.
Was This Post Helpful? 0
  • +
  • -

#14 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1907
  • View blog
  • Posts: 3,953
  • Joined: 11-December 07

Re: CamelCase or PascalCase

Posted 17 June 2010 - 06:27 AM

I tend to go with java conventions. Keeps my code readable.

ClassNames
variableAndMethodNames
CONSTANT_NAMES

Hungarian notation gets added in whenever it clarifies things. (I would never use the example in your poll though)

Particularly in unit tests I do things like:

testCustomSort_arrayWithDuplicates

Basically, I use whatever convention makes my code easier to understand.
Was This Post Helpful? 0
  • +
  • -

#15 SpeedisaVirus  Icon User is offline

  • Baller
  • member icon

Reputation: 114
  • View blog
  • Posts: 855
  • Joined: 06-October 08

Re: CamelCase or PascalCase

Posted 17 June 2010 - 07:35 AM

I primarily use camel case without underscores but sometimes when writing C I catch myself using them...just feels...right. No idea why but it's how I roll.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2