Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the number and person of naming in the process of .NET development

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to analyze the number and person named in the .NET development process, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

We all understand the importance of naming. If we pay constant attention to naming, we need to consider the verbs and nouns in naming, especially the person of verbs and the number of nouns.

Let's discuss these two aspects.

The number of nouns

First of all, let's look at the quantity. There are obvious differences between singular and plural nouns in semantics. In order to improve readability, quantity needs to be carefully considered. For example:

Property: Keys and Count in System.Collections.Generic.Dictionary are good examples. Field is similar to this; noun in method name: getElementById and getElementsByTagName that we are familiar with in JS

Local variables: we are more likely to encounter local variables than attributes. For example, if you use variables to represent a person's name, you can use string name;. If you have multiple names, you can use List names.

Generally speaking, the semantics of singular expressions are? (0 or 1); the semantics of plural expressions are * (0, 1 or more). The number of nouns is easy to understand and the relevant rules are easy to follow.

The person of a verb

Let's consider the person of the verb. Among the objects that need to be considered naming, including namespaces, types, and members of various types, only methods are verbs that semantically represent a behavior. For its person, let's take a look at an example in the .NET Framework. In System.Collections.Generic.Stack, there is a Contains (T item) method for code like this:

If (theStack.Contains (1)) {/ / Do something. }

It reads like: if the stack contains 1, relatively smooth. Should all methods be named this way? No. This is not the case with the other two methods, Clear () and Push (T item), which is very confusing. Write it into code first and have a look.

TheStack.Push (3); theStack.Clear ()

Try to read it as a sentence as above: the stack push 3; the stack clear, which is grammatically wrong and looks like the third person. I'm not sure why, but I can only try to explain it. After examining multiple set types and other types, it is found that all the places that use the third person are predicate functions, except Contains (T item) above, and Directory.Exists (string path). I wonder if this is the naming rule among them?

Also consider comments.

To some extent, comments are also a kind of code. One is XML documentation comments, which we can follow in the .NET Framework, where third person is used for both types and type members. Other general comments should also follow this rule.

The above is how to analyze the number and number of people named in the .NET development process. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report