From the other thread in this forum we got "The One True Brace" as a brace style and another type (I forget the name of that one). What about variables? I name my variables by capping the second word and each word after that such as:
$myVariable
int myVariable
int myVeryLongVariable
I notice people often use different styles or in really bad coding, no styles.
I often see all words capped.
$MyVariable
int MyVariable
and in bad coding
myVariable
int MyVeryLongVariable (notice the first word isn't capped and then capped?)
My question is: What are these styles called and which do you use? Is there a correct way because I've taken several programming classes and read even more books. Each teacher/author will have a different style.
IME, the first style is called camelCase, and the second PascalCase. Note that this Wikipedia article, however, says they are both camel case and should be called lowerCamelCase or UpperCamelCase (edit: that used to say UpperPascalCase, which is wrong...oops). I say I've never heard of such terms - but do realize that wiki engines in general call PascalCase camelCase.I submit the .NET Framework Design Guidelines on Capitalization in my defense.
For .NET, Microsoft has the above design guideline for the BCL. I'm sure Java has something similar. It's probably advisable to follow those guidelines, so here's the relevant portions of the .NET one:
a. camelCase for parameters, local and (non public) member variables
b. PascalCase for classes, enum types and values, properties, functions, events, readonly statics, public member variables, interfaces, namespaces, and acronyms more than 2 letters long
c. no Hungarian notation
d. no prefix for member variables (I'm not entirely sure this is in there, I know it recommends against underscores for class names, but others have stated it does as well for member variables. I do know, however, that you cannot be CLS compliant with an underscore prefix)
And, now that I have given the "official" recommendation, here's how I actually do it for both VB.NET and C#:
a. camelCase for local variables and parameters
b. PascalCase for pretty much everything else
c. _camelCase (camelCase with a leading underscore) for private or protected member variables
d. ALL_CAPS_WITH_UNDERSCORE for constants
e. Hungarian notation only for web or WinForm control variables
IOW, it's a strange mix of .NET guidelines and my own peculiariaties. Oh well, at least I'm consistent.![]()
Last edited by brackett; 05-30-2006 at 04:06 PM.
Wow, nice post. I've never done it so. I've always just used CamelCase (Upper) or PascalCode for everything. I guess each person should read up and then default to their own style.Originally Posted by brackett
.... I need to change my style now .....
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks