Pascal casing or Camel Casing for C# code?

2019-01-14 10:43发布

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.)

14条回答
Explosion°爆炸
2楼-- · 2019-01-14 11:17

The day when i quit programming - its when Microsoft will make CamelCase in C# as standard. Because my grown logic has many reasons for PascalCase, unlike kid's logic, who cares only shorter names or easier to write.

And BTW: CamelCasing comes primarily from C++ STD library style, the native old language inherited from C. So Java inherited from C++. But C# - is entirely new language - clean and beauty, with new rules. Oldfags must programm on Java or C++, new generation people must programm on C# - and they should never interact.

Consider this example: 1) PascalCase: list.Capacity.ToString(); 2) CamelCase: list.capacity.toString();

In (1) we have CAMEL CASE in long TERM!!! means listCapacityToString. In (2) we have bullshit: listcapacitytoString.

Thats how i read. And why CamelCase is illogical for itselt. I could kill for PascalCase, never touch it, kids of any age.

Microsoft - forever or until they use PascalCase.

查看更多
爷的心禁止访问
3楼-- · 2019-01-14 11:18

I like the coding conventions laid out in the Aardvark'd project spec

查看更多
Fickle 薄情
4楼-- · 2019-01-14 11:21
Root(大扎)
5楼-- · 2019-01-14 11:23

I (and my team) prefer to reserve initial capitals for class names.

Why? Java standards propagating, I think.

查看更多
趁早两清
6楼-- · 2019-01-14 11:24

I guess you have to put up with what the coding standard says for your place of work, however much you personally dislike it. Maybe one day in the future you will be able to dictate your own coding standards.

Personally I like databases to use names of the form "fish_name", "tank_id", etc for tables and fields, whereas the code equivalent of the database model would be "fishName" and "tankID". I also dislike "_fooname" naming when "fooName" is available. But I must repeat that this is subjective, and different people will have different ideas about what is good and bad due to their prior experience and education.

查看更多
啃猪蹄的小仙女
7楼-- · 2019-01-14 11:28

I use what the Framework uses, as it's the de-facto best practice. However, so long as the code in your company is consistently using their style, then you're much better off getting used to it. If every developer has their own standard, then there's no standard at all.

查看更多
登录 后发表回答