So let's start our discussion in the first half,How to Use Case?
As we all know, there are two most common methods for Case sensitivity:
Pascalcasing
Camelcasing
Pascalcasing: It capitalized the first letter of each word in the identifier (including the first letter of two or more words), such as WebClient. Of course, there are some special cases such as system. i/O, where I/O is the abbreviation of the two words in uppercase, in fact, this is in line with the pascalcasing method.
Camelcasing is used to uppercase the first letter of all words except the first word, for example, propertyname.
In practice, the namespace, type, and member names are generally named using the pascalcasing method, and the parameters are named using the camelcasing method.
As follows:
Identifier |
Case sensitivity |
Demo |
Namespace |
Pascal |
System. net |
Type |
Pascal |
Streamreader |
Interface |
Pascal |
Ienumerable |
Method |
Pascal |
Tostring |
Attribute |
Pascal |
Name |
Event |
Pascal |
Onload |
Enumeration |
Pascal |
Filemode |
Parameters |
Camel |
Value |
The above example illustrates the case-sensitivity naming method in some development scenarios, and also the "field". Microsoft officially recommends the Pascal case naming method, however, in my actual work, I prefer to use the access modifier to determine the case-sensitive naming method, for example:
Public, internal, and protected use Pascal
Private adopts camel
Of course, this is my personal habit. I also discussed this kind of habit within the company and eventually kept this kind of solution.
Another scenario is the naming of Io. I/O is the abbreviation of two words, and I/O is the official name of Microsoft, so everyone is familiar with and accept it. However, I personally think that I should not use this abbreviation in actual work, in addition to naming your abbreviations, you can get a clear picture (in this case few). Otherwise, do not use the acronyms to name them, because such names will affect Alibaba Cloud when people are unfamiliar with them.
How do I select an appropriate name for the identifier?
I think there are several points:
1. Select an easy-to-read name
A name that is easy to read is very important.CodeFor readability, you can understand the usage of methods, attributes, events, and so on before looking at the code logic.
2. Readability rather than simplicity
Some people may think that the shorter the name length, the better it is, but the brief name may make people feel that the code is "clean", but it is not necessarily clear about the functional logic, such: getint without getlength looks more intuitive.
3. Do not use underscores, hyphens, or other non-alphanumeric characters. In fact, it is not very good to name numbers, I remember that it was useful when we used ESRI's ArcGIS Engine for Embedded Development in GIS... The naming method of 2 was confusing at the time. Of course, it was just a personal experience. For myself, I had to try not to use numbers.
4. When it comes to naming, I have to mention the Hungarian naming method used by some companies in the past, that is, using lowercase data type abbreviations as the prefix of variable names, to some extent, this naming method does bring us some convenience, such as proper use can bring us better readability, but it also increases the maintenance cost and obfuscation caused by improper maintenance. Because it requires a large number of design guarantees for various types in the early stage, this will greatly increase the development and maintenance costs, so it is not recommended to use the Hungarian naming method.
Do not use acronyms that you are not sure about to give a name overview. For example, using showwindow is easier to understand than showwin.
Use common names such as item, length, count, and value as much as possible, because such names sometimes indicate the purpose of a word as 50%.
Finally, the int type exists in C #, but we all know that the int type is actually system. the alias of int32, and stirng is the alias of string. We should avoid using the alias when designing our own program, because the alias may cause code confusion and is not easy to read.
And how to use certain terms?
Avoid usingProgramming LanguageSpecial names, such as char, float, double, object ........
The names of specific language-specific types are not listed here.
The above is my personal understanding of naming conventions, which may not be very thorough. You are welcome to discuss and give your comments or suggestions.
Reference document of this article-. Net Design Specification conventions, idioms and patterns
-- The younger brother is not talented. You are welcome to reprint it.