Have you ever used this wonderful C # annotation? How to view,

Source: Internet
Author: User
Tags array definition net serialization

Have you ever used this wonderful C # annotation? How to view,

Reading directory

  • 1. C # annotation Method
  • 2. Is this a wonderful comment?
  • 3. Use it for your own purposes.
  • 4. Finally, guess who wrote it.

Although I am not a professional developer or a non-professional developer, I have been using C # stacking code to solve my daily small problems. Including your own research, it is also implemented and tested using C. I have a special liking for C. Although many of C #'s advanced technologies won't be used and I don't know much about it, I always know more or less about it. Because of the many open-source components and technologies, I often translate other people's code (most of them are foreign), so I often translate and summarize them, for example, the first two machine learning articles I translated:

[Original]. NET platform machine learning component-Infer. NET serialization (I) Introduction

[Original]. NET platform machine learning component-Infer. NET serialization (ii) Bayesian Classifier

In fact, the translation has been in progress and has been completed a lot, but there is no time to sort out and post it for everyone to share. But not long ago, when I was reading the Code (which is also part of the translation), I found a very strange comment, So I simply flipped through the search engine and summarized it, at the same time, let's talk about how to look at this writing method.

Many people have different opinions on code comments, including some time ago, there was an article in the blog Park News, which probably meant that there were comments, which showed that the Code itself was very bad, therefore, add a comment. Of course, I do not agree with this point of view, although there is a little truth.

Statement: I may have little knowledge, but many people may have seen and used it. The first time I saw it, I was a little shocked. Of course it must comply with the syntax requirements, so I wrote it out, take a pat.

Return to the annotation method of directory 1.C #

C # personnel should be clear about it. C # has three methods to mark and comment:

1.1 three-slash (//) Method

It is generally used before a class or method. The following code is used:

1 /// <summary> 2 // here is the comment ..... 3 // Latent Dirichlet Allocation (LDA) model implemented in Infer. NET.4 // This version scales with number of documents.5 /// </summary>
1.2 double slash (//) Method

It is usually a comment on temporary variables, attributes, and so on. Of course, it can also be used before the class or method. It is a comment anyway. The following code:

1 //---------------------------------------------2 // The model4 Range D = new Range(NumDocuments).Named("D");
3. Block annotations (/* XXXX */)

It is generally used for a continuous comments code block, as shown in the following code:

/* This program is no longer useful * because we found that the bug was just a false alarm * our system will not be restored to 1/1/1900 */

In my impression, the C # annotation identifiers should be these three types. Of course, we will not discuss other annotation type parameters.

Return to the directory 2. Is this a wonderful comment?

You must have used the above three annotation methods. It is estimated that they are the same as me (most of them). Write them in front of the class, attribute, or temporary variable and start a line.

What I'm talking about here is not separated from the three methods, but the location of its comments. But when I browsed an open-source code, I found this comment. At that time, I was surprised. Then I thought about it, let's take a look:

 

The above Code includes the three annotation methods mentioned above. The red box contains the wonderful notes that I have mentioned. The/**/block method is used to write the comments in the middle of the array definition, without a doubt, this can certainly be run. I did not expect this, but it may be limited to my own way of thinking.

According to my understanding, the purpose of such a comment is that the variable in this Code contains a large amount of information, so that the writing is more straightforward. But is it redundant? Can it be explained directly on the variable?

In turn, think about it. In some complicated problems, variable initialization may be very complicated. The array length here is 2. If it is 20, what should we do? In this way, the write advantage will come out, so that the code users can see at a glance.

Another piece of code similar to the annotation is found in one place, which is like this:

Return to the directory 3. Use it for your own purposes.

At the beginning, I was a little unable to accept it. For this reason, I recalled a lot of code I had written, and I turned it over specially, in the end, I felt that this method can be gradually adopted in my own code in the future. On the one hand, it was because I did not expect it to be used in the past, where is the limitation of thinking, and I am used to setting up another line of explanation; on the other hand, there is indeed a lot of code that requires such a clear annotation. Maybe your code and architecture capabilities are insufficient. In many places, coupling is very serious and you have to express your thoughts through many annotations, there are a lot of variables, such as initialization, it is very clear, look at the modified code example:

3.1 comments before

In the previous code segment, there was a fixed limited list of company numbers. However, during actual development, you often need to know the corresponding name. Of course, you can search for it in the database, but I can't see it in the code, so I wrote this:

// Name of an authoritative company (in sequence): "Macao", "jinbao Bo", "Libo", "William Hill", "Wei de", "10BET", "bet 365 ", "Snail I" static List <Int32> AuthCompanyIdList = new List <int> () {247,250,251,252,253, 1,469,179 };

So in the past, there was an error or some information was manually checked, and the numbers were commented out. Although the number was very small, it was occasionally used. So after seeing the above annotation method, I modified it.

3.2 current annotation Method

The modified code is like this. It is not intended to be changed. After this change, I feel much better. I can understand the meaning of this Code.

Internal static List <Int32> AuthCompanyIdList = new List <int> (){
247/* MACAO */, 250/* jinbaobo */, 251/* Libo */, 252/* William Hill */, 253/* Weide */, 1/* 10BET */, 469/* bet 365 */, 179/* snai */
};

Which one can be used? What's important is that you can understand it easily. If you think it is useful, you can use it. If you think it is boring, skip it.

Go back to the directory 4. Finally, guess who wrote it.

Coding should be easy. If you can write your code very elegantly and understand it well, it would be better. Finally, let's entertain myself and guess where the code comes from?

A: A. NET example of A commercial machine learning algorithm software;

B: A. NET implementation blog example of a foreign open-source machine learning algorithm;

C: An Example of machine learning algorithm implementation by Microsoft researchers;

D: the. NET version implemented by a machine learning algorithm py in the Python open-source community;

For more information about how to view and such annotations, see the annotations .... It may be that I have made a big fuss... Understanding, constantly improving details, and constantly improving ..

Answer in the afternoon ....

The first code comes from the Cambridge Research Institute at Microsoft and is a Demo code of Infer. NET.

The second code comes from the instance code of the open-source machine learning component Accord. NET Framework.

Related Article

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.