Causes of poor code generation (4) manager misleading

Source: Internet
Author: User

Poor qualityCodeAnother cause is the manager's misleading behavior. The specific misleading behavior has the following forms:

1. inexplicable code specifications

Code specifications are designed to enable the teamProgramThe code written by the employee is written by a person. It is a good thing, but if the code specification is just copied during code formulation, the code specification is likely to become a culprit that damages the quality of the Code.

A. Add comments to each line of modified code.

Add comments to the Code modified in each line when no version management tool is available. This allows you to compare the modified Code.
This code modification method leads to a very important feature-refactoring-which cannot be used. This is because a lot of code is changed every time you refactor, and no comments are added.
The correct method is to add the modified resume to the version tool.

B. Reduce the amount of code modified during modification.

When modifying the code, try to reduce the amount of code modifications to reduce the impact.
If you want to add a condition for processing a row, the original processing cannot be dynamic. In this way, the Code is not indented. When several such codes are accumulated together, the code is basically not readable.
Besides, the code version management tool provides the code comparison function and can compare any two versions.

C. Do not delete the old code when modifying the code.

Leave the old code behind when modifying the code, and do not delete the old code. This is to understand the intention of code modification.
Following this code specification will make code a lot of trouble, and sometimes the old code can be annotated in segments without reference. In some cases, a meaningful statement is split into several comments in the middle into louvers.

D. The number of comments and code must reach.

I am afraid it is not so easy to understand without comments in the code, but I am afraid it is not easy to understand comments everywhere in the code.
When the amount of comments is required, the comments are changed to comments for comments.
I will talk about how to annotate in "How to Write self-expressing code -- change programming habits -- Comment.

E. Each line of code cannot exceed 80 characters

In the past, due to the cost of coding tools, some people use a non-IDE environment to view the code, and some people need to print the code, so each line of code should not exceed 80 characters. In order to obtain the compatibility of reading.
However, the current monitors are dominated by wide screens. Each line of code contains only 80 characters, and a large area is left empty on the right. In addition, the naming of advanced languages is usually not short, and the class-method-condition indentation is added, basically 80 characters can not even be used to hold a long judgment statement. The limit of 80 characters per line leads to a line break. This obsolete rule has no value except for reducing the readability of the Code.

F. Each method cannot exceed 200 rows

The method cannot be too long. Code that is too long may cause reading difficulties.

Why 200? It is said to be statistical. Most code should be kept within 20 lines, and a few code should not exceed 200 lines. Therefore, this rule is better than to stipulate that the number of methods should not exceed 20; if the number of methods must exceed 20, the number of methods should not exceed 200. If 200 rows are defined, most of the 50 rows are not in violation. As a result, the number of medium-scale methods is too large.

G. The domain variables must be defined as private.

Domain variables are defined as private to increase security.

Define the domain variable as private and add getter and setter. This is no different from defining it as public. The public type of the domain variables should be defined according to the specific application, and cannot be completely defined as private.

H. Do-while is not allowed.

It is not allowed to use do-while because do-while is hard to read.

Therefore, some codes are written as a group of operations outside do-while, and repeated in do-while.

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.