About. Net Program Design-Naming Convention (I)

Source: Internet
Author: User
Tags alphanumeric characters

After several years of experience, several companies have also participated in the design and development of some project products. I dare not say anything about it. I can only say that there has been some technical accumulation. I want to write it out and share it with colleagues.

I have been on various technical forums and have been admiring the technologies written by other colleagues.ArticleI have to say that some of them have benefited me a lot. How can this problem be solved? We must have our experts. No one who is engaged in technology can be proficient in everything. So I have always wanted to share with you what I have accumulated over the past few years.

Let me introduce it first. I have been working on it for several years. net B/S, C/S direction (haha, it was selected because it was Microsoft's platform. from net framework2.0, 3.0, and 3.5 to the current 4.0, I have to say that Microsoft is indeed launching the Framework version so quickly, and the framework is becoming more and more comprehensive and more powerful. I have to say that such a huge framework and a large development team behind it can continuously update seamless integration in a short time, only companies like Microsoft can do this! Imagine domestic projects over the past few years (although they cannot be compared with Microsoft's framework), if they can be quickly updated and seamlessly integrated like the framework, I personally think that in addition to a technically competent, highly cohesive, and highly executive team, there must also be a set of standards that adapt to the needs of the teams in the industry. Only with standards can we have specific constraints and specific directions, so we can control some things.

In this way, we are the most commonly used technical standards.ProgramNaming rules. Maybe there are countless articles on naming conventions on the Internet. I am not following others. I just want to talk about my experience.

It's time to talk about it.

I mainly want to elaborate some experiences on naming conventions through two parts, one of which is chat.. Net Program Design-Naming Convention (I), which will mainly discuss how to use case, how to select an appropriate name for the identifier, and how to use certain specific terms; another part is chat.. Net Program Design-naming conventions (below), which will discuss naming conventions for namespaces, types, members, parameters, assembly, and resources.

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.