C# naming convention for constants other than Pascal and All Caps
In my project currently we are using All caps as naming convention for constants. I would like to change it and I'm OK with Pascal Casing but my team lead has a strong argument that it will not visibly distinguish constant from Properties and other Types.
Please help me with any other suggestions.
RESULT
As @Paolo Tedesco and most of the people here thinks, I will stick to ALL_CAPS
. Anyways I don't have开发者_如何学Python other option also now as the argument provided by @24x7Programmer couldn't change my team lead's mind. Now further I can't argue on this little issue.
Thank you every one for your suggestions.
MSDN sets out naming guidelines for C# quite clearly. If someone new were to come and join your team, would you really want to waste time explaining to them your conventions? If they were to dive straight into the code without knowing your conventions, would you really want them to waste time in confusion trying to muddle out what's what and spending most of their time coding used to your conventions? People need to accept that each language has it's own set of conventions and realise that the best practice is to stick to them. It'll save you, your team members and new members a lot of time and headache.
Sorry to sound so melodramatic, but I find it hard enough naming classes and members. The less time I spend thinking about upper-casing, camel-casing and pascal-casing the better.
In our projects we usally define a separate class for constants and use only Pascal naming for them. So we refere constants something like this:
Functionality1Constants.ThisIsAConstant
There are official Naming Guidelines for .NET, to which most .NET developers adhere. For me, you'd need a much better reason than "it will not visibly distinguish constant from Properties and other Types" to deviate from these guidelines.
If you follow them, your code will look like .NET code, rather than like C++ code that is being compiled with the C# compiler.
I personally think that ALL_CAPS_CONSTANTS_LOOK_UGLY, but your team leader has a good point in saying that they are easily distinguishable from everything else.
What is your point for changing the convention? If it's only an aestethical preference, then I think that you should adapt to the convention in place - as a professional developer you must be able to read and write code also if it does not conform to your preferences...
This is a subjective question. There isn't an iron-clad proof that all-caps is a bad idea, so just go with the flow. This kind of issue isn't worth going to war over.
Why do you have to be able to distinguish constants easily? In C++ and C it made sense that you wanted to be able to distinguish macros easily, but I can't think of any good reason for that being needed. I used to use all upper case out of habit, but mostly changed to Pascal casing now since it fits better with the rest of the code.
Edit: Though I agree with the other answers that it's very subjective anyway, so if you've already got a standard, I can't say that it would be worth changing it.
First decide what's important for constant names, and let that lead the convention. Consider:
- That it's a constant
- Readability
- Meaning of the name
- It's data type
I feel that the readability and meaning is most important. The data type can sometimes be important, but then it should be evident from the name anyway. So, I would skip trying to make constants stand out just because they are constants, and use the same convention as for naming variables or properties.
精彩评论