Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pascal casing or Camel Casing for C# code?

I've been arguing with my coworkers about Pascal casing (upper camel case) vs. lower CamelCasing. They are used to lower camel casing for everything from table names in SQL databases to property naming in C# code but I like Pascal casing better, lower camel casing for variables and Pascal casing for properties:

string firstName; public string FirstName { ... } 

But they are used to this:

string _firstname; public string firstName { ... } 

I try to keep up with their "standard" so the code looks the same but I just don't like it.

I've seen that at least the .NET framework uses this convention and that is how I try to keep my code, e.g.:

System.Console.WriteLine("string") 

What do you use/prefer and why? I'm sorry if somebody else asked this question but I searched and did not find anything.

Update: I've given a method example and not a property but it's the same. As I stated in the first paragraph my colleagues use the Pascal convention for everything (variables, methods, table names, etc.)

like image 996
Gustavo Rubio Avatar asked Sep 29 '08 16:09

Gustavo Rubio


People also ask

Should you use camel case in C?

C++ code. Use CamelCase for all names. Start types (such as classes, structs, and typedefs) with a capital letter, other names (functions, variables) with a lowercase letter.

Should I use PascalCase or camel case?

Camel case (ex: camelCase) is usually for variables, properties, attributes, methods, and functions. Snake case (ex: snake_case) is commonly used in scripting languages like Python and as a constant in other C-styled languages. Pascal case (ex: PascalCase) is mainly reserved for class names, interfaces, and namespaces.

Why is PascalCase used in C#?

Pascal case naming convention The use of a single uppercase letter for each additional word makes it easier to read code and discern the purpose of variables. The term Pascal case was popularized by the Pascal programming language. Pascal itself is case insensitive, so the use of PascalCase was not a requirement.

When should I use CamelCase?

CamelCase is most used in places where white space is not allowed for technical reasons. This can make the phrase hard to read or ambiguous. An example of an ambiguous phrase in programming is chartable, which can be interpreted as char table (a table of characters) or chart able (having the ability to be charted).


1 Answers

A link to the official design guidelines might help. Specifically, read the section on Capitalization styles.

In the grand scheme of things, Pascal vs Camel doesn't matter that much and you're not likely to convince anyone to go back over an existing code base just to change the case of names. What's really important is that you want to be consistent within a given code base.

I'm just happy as long as you're not using Hungarian.

like image 115
Joel Coehoorn Avatar answered Sep 18 '22 06:09

Joel Coehoorn