first, the code quality
Software is a product that is delivered to the user and is experienced by the user; The code is the correct and detailed description of the software, so the quality of the code is related to the quality of the SOFTWARE PRODUCT. Although software quality is not equal to code quality, defects in code can seriously affect the quality of software products. Therefore, it is worthwhile to invest in improving the quality of the code.
second, the quality of software products can usually be measured from the following six aspects
functionality, i.e. whether the software satisfies the customer's business requirements;usability, which is how much effort is required to measure the user's use of the software;reliability, that is, whether the software can always be in a stable state to meet the availability;high efficiency, that is, how much physical resources are needed to measure the normal operation of software;maintainability, that is, to measure how much effort is required to adjust the software that has been completed;portability, that is, measuring whether the software can be easily deployed to different operating environments;
Iii. specific experience in improving code quality
1. Never copy codeavoid repetitive code at any cost. If a common code snippet appears in several different parts of the program, refactor it and put it in a function of your own. Repetitive code can cause your coworkers to be confused when they read your code. Duplicate code, if modified in one place and forgotten in another place, generates bugs everywhere, and it can make your code bulky. 2. Test your completed Codeyou know what your code can do, and try it, it really works, but you actually need to fully validate it. Analyze all possible boundary conditions and test it to work as expected under all possible conditions. If there are parameters, pass some values outside the expected range. Pass a null value. If possible, ask your colleagues to look at your code to see if they can break it. Unit testing is a common method of reaching this purpose. 3. Code Reviewbefore submitting your code, ask a colleague to sit down and explain to him what changes you have made. In general, you can find errors in your code when you do so without the need for a colleague to say a word. This is much more effective than reviewing your own code. 4. Write self-explanatory codeNeedless to say, annotations are an important part of programming, but it's a good idea to be self-explanatory, because it allows you to understand it when you look at the code. Function name Variable name to choose carefully, good variable/method name in the language semantic environment, people who do not understand programming can understand. 5. Do not use pure numbersembedding numbers directly in your code is a bad habit, because it doesn't explain what they represent. Worse when there is repetition-the same number appears in multiple places in the code. If only one is modified and the other is forgotten. This causes the bug. Be sure to use a named represented to represent the number you want to express, even if it appears only once in the code. 6. Do not do manual laboras a series of actions, human beings always like to make mistakes. If you're doing a deployment, and you're not doing it in one step, you're doing something wrong. As much as possible to automate the completion of the work to reduce human error. This is especially important when you are working on a task that is very heavy. 7, do not try to kill the code to speed up, find a more efficient algorithm may be more effective. 8, the code to do first, in the fast. Make it reliable, and let it go faster. Clean up the code before it gets faster.9, when a function is found to have the following characteristics, you need to consider the extraction function(1), too long(2), nesting layer is too deep. (3), natural tiles, need to use annotations to describe the program block(4), the judgment condition is too complex(5), certain branches of function change constantly(6), parameter is too complex(7), logical repetition10, local variables should use a single11, programmers should be a neat code style as a habit, always aware of the importance of clean code and constantly improve the refactoring skills12. About Annotations(1), if the short function can be described, then use the child function instead of the comment itself. (2), to ensure that the comments and code expression of the same intent, or lose the meaning of the annotation. (3), in important places to write comments, do not annotate the flying, simple repetition of the function of the code is meaningless. Make every comment worthwhile. Do not comment excessively. 13, about when to rewrite the codeThe development team should reserve 20% of the time to maintain the refactoring of the legacy system. The remaining time is used to develop new features. whenever possible, the parts to be reconstructed are incrementally modified to make the user feel the improvement of the product, even if the working time is prolonged.
How to improve code quality