How to write code to programmers seven tips

* 10 minutes, 20 minutes or even 30 minutes to think about what you need, what design patterns (if any) to be encoded for you to think about things. Really want to think about it, you will be very glad "wasted" those few minutes when you have to change or add something to the code, but only took you 30 minutes instead of 5 hours.
Here Insert Picture Description
1. Think before coding
10 minutes, 20 minutes or even 30 minutes to think about what you need, think about what kind of design patterns (if any) for you to be coded things. Really want to think about it, you will be very glad "wasted" those few minutes when you have to change or add something to the code, but only took you 30 minutes instead of 5 hours.
2. Comment your code
really, there is nothing to check their code than two months later, but do not remember it used to do worse in the. NOTE All important elements, the obvious course to avoid the bar.
3. Write clean code
patchwork. Use spaces. According to the modular functionality of your code. Read Robert C. Martin wrote "Clean Code", very helpful. In addition, the code follows the conventions / standards (e.g., Java Code Conventions), especially if they are shared code.
4. The reconstruction
is no way with those who like super long. This is usually (almost always) it means that you mix the function. The method for the separation of code more manageable. Also makes the code more reusable.
5. Do not copy and paste the code
if you have the same code blocks of two or more, then you have done something wrong. Read Article 4.
6. Use meaningful names
, although int variable named "elligent" or char as "mander" is very funny; however, this name does not indicate what the variable is used to do.
7. Test Code
Test, test, test, or test. Test your code. Do not wait to come back after the test program has been done, or when you find a huge bug, but do not know where it comes from, you'll regret
7b. Automated testing is usually valuable. It also helps save a lot of weight and regression testing time.
8. Learn to debug
a lot of novice programmers, accustomed to manage things and not know how to do, and every time you encounter problems println. Wrong. Sometimes, I even can not find the bug, and check the "missing" println waste of time.

Guess you like

Origin blog.csdn.net/xinshiedu/article/details/92964613
Recommended