Code specification and code review

Source: Internet
Author: User

1. Discussion of code specifications

Do you need code specification to write a program? I think, of course, the norm has to have, but also must be reasonable.

Why do we need code specifications? The code specification is to stipulate that certain formats in the code must adhere to certain conditions, such as indentation, variable naming, annotations, and so on. When a reasonable specification is made, not only does the code itself look beautiful, but everyone is easy to read and the maintainability of the code is greatly enhanced. For example, the variable name used in a program is input_msg,output_msg,decipher, with spaces between each symbol, while the B program uses meaningless letters such as a,b,c as variable names, and local variables of the same name are repeated in multiple functions. This way, once a bug in the program needs to be debugged, a program will find the wrong location faster than the B program. In this view, code specifications are essential. Let's take a look at people's misconceptions about code specifications.

Some people think that the "norm" is the product of bureaucracy, it will only reduce the efficiency of programming, wasting time. I beg to differ from this view. If the code of programming represents bureaucracy, what is the norm that is not bureaucratic? No rules inadequate surrounding area, if there is no programming code, then everyone to write programs are arbitrary, code is a mess, like things piled up warehouse, want to read it will be very difficult. This view, which blindly treats the norm as a restraint, is obviously undesirable.

Others believe that I have my own norms and principles, and that I do not have to abide by the norms and principles imposed on me by others. In fact, having their own norms and principles is not wrong, otherwise the same as no rules. But this view is too individualistic, others want you to abide by certain norms and principles, you are "this and my principles conflict" and strongly rejected. However, when writing a large program, it is never enough to rely on individual efforts, and it requires close cooperation from the team. You have to follow your own ideas completely, regardless of other people's advice or discourage, then the strength of the team will not be able to maximize the play out.

Another word, OK, I admit the code is normative, but I also hate the same, so the code specification should allow many exceptions. This view is not produced by the purpose of the Code specification itself. Code specification is not a one-size-fits-all rule that each person's code must be in the same style, but only in the key parts of the code to seek some unity. Think that the laws of the state will require every citizen to live in the same way? The law only prescribes what you should do and what you should not do. Code specification is the same, but it is not as mandatory as the law, but more like a guide to guide you how to write beautiful, easy-to-read code. From this point of view, reasonable code specification, is not to produce what "exception".

However, some people think that "I most will make norms, I set the most reasonable norms, so you have to listen to me," is tantamount to their own views imposed on others, contrary to the do unto others come back haunting truth. A reasonable standard should be the whole team after careful deliberation, and agreed that everyone must abide by, both to allow everyone to accept, but also have a certain guidance. The individual requests the collective to follow oneself completely, is regards oneself as the bureaucrat emperor, is does not respect the teammate's affection. You don't respect your teammates, how can your teammates respect you?

In summary, we need a reasonable code specification. In a good program, these code specifications should be embodied everywhere.

2. Code review Examples

recently I reviewed the code of one of my classmates and the results were as follows:

When the correct command is entered, the program can correctly generate and calculate the problem, and can correctly evaluate the answer to the existing question, indicating that the program realizes the basic function.

The program is written in C #, the use of object-oriented programming ideas, the program of different functional modules into different source programs, can effectively reduce the number of individual source files, write code in accordance with the specification indentation and add spaces, appear concise and beautiful. Each variable, the method uses the meaning clear, the simple word, the program each line code is not long, the overall readability is good. The program has no duplicate, redundant code, and no unnecessary global variables.

When the wrong command is entered, the program can report the exception and output in time. After many tests, no cross-boundary errors were found.

The program adds annotations to the necessary location, which enhances the readability of the program.

If the program can be equipped with a detailed and accurate documentation, indicating the specific functions of the program, operating details, etc., it will be easier to use and maintenance.

Code specification and code review

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.