Four basic coding principles

Source: Internet
Author: User

It can also be regarded as a standard for judging the quality of the Code. At least when you write the code, there are rules to follow. What you write is not necessarily comprehensive. You can add it.
1. The code is not repeated and similar. Try to reuse the written code as much as possible. Reuse refers to calling, not copy and paste. This is the top priority. Many technologies in software development aim at reuse. The more code reuse, the more opportunities to be tested, the code is more robust. Once there is any problem, you only need to modify the code in one place, and the writing and testing time can be effectively reduced. Function is the most common and simplest method for code reuse. Therefore, you must develop the habit of writing multiple functions. No matter whether it is a beginner or an old programmer, No matter what code we write, after writing it, check whether there are similar code. Some must try to eliminate it. Let's look at whether the written code can be reused in the future, in fact, this is the so-called refactoring, and there are more refactoring. The next time you write, you can directly write non-repeated code, and the level will naturally improve.

2. The code is easier to understand. First, the name should be standardized. Try to name it in a way that you can understand. Writing code again does not show how high your syntax is. Try to use easy-to-read statements, and it looks easy to find errors. In my course, I only use the simplest statement to write a program. I may not be able to take the test, but I still need to write a software. In our C language computer Level Examination, the basic knowledge part emphasizes the ease of coding, while the questions behind the examination appear a line of difficult and error-prone statements, self-conflict.
3. The code must have a good format. This is easy. I have a simple format. A variable occupies one row, "{" and "}" occupies one row, and the next line of "{" needs to be indented, other rows must be aligned, and the corresponding "{" and "}" must be aligned. What I saw in a book is very useful. Remember.

4. Add comments. Note: It mainly describes variables, functions and classes, algorithm descriptions, author information, writing time, modification records, etc. You can find a written comment template on the Internet, some development tools can generate. In Java and C #, program documents can be automatically generated according to certain format annotations.

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.