For a long time, I have focused on improving code quality, and I have made some attempts to do so. I thought this topic might be of interest to you, and I would like to share some of my experiences on improving code quality. Do you know how to write quality code? Don’t just start writing code. Think before you start. Here are 10 tips to help you write quality code:
1. Reframe your mindset
Don’t just start writing code, learn as many ways to refactor as you can, learn how to think about refactoring, and learn that refactoring doesn’t necessarily mean refactoring the original code, but letting yourself figure out how to do it before you do it.
Figure out what you need before you start
After seeing the requirements, there must be more or less some problems, or misunderstanding, or problems in the implementation of functions, at this time, we must communicate clearly, otherwise, there will be more problems in the future.
3. Document, too
Many people may feel that the document is not read, it does not matter whether to write. However, the document is not read, still have to write.
Most of the time, the role of the document is not used for communication, but for recording, most of the requirements or through oral communication, but do not write documents to record, the subsequent easy to quarrel.
4. Code comments must be written
You have to write comments, if you don’t write comments, after a long time, you can’t even read yourself. Also, you can’t be in charge of a project alone, and comments can make your code accessible to other colleagues,
Communicate requirements and make changes
Don’t expect the demand to be stable, product demand is constantly adjusted and optimized according to business needs, changing the demand is normal, don’t always complain, adjust the mentality is the absolute truth.
6. Deal with business relationships
No matter it is technology or business, we should not try to be superior to each other. We should complement each other.
Technology that does not serve the business of the company is worthless. The only reason is that the company makes money. Don’t worry about changing the company’s needs and business.
Don’t take any chances
If something feels like a bug, it’s a bug. Don’t take any chances, be sure to optimize the place where you feel you can get bugs, and leave no future problems.
8. Test yourself a few times
Don’t just write it and throw it to a tester. Test it a few times by yourself. You’ll be more familiar with what you write, and it’ll be easier to find problems. Make sure the quality of what goes through your hands.
9. Try to solve problems on your own
If you have a problem, try your best to solve it yourself. If you can’t solve it, ask for help. No one is obligated to clean up after you in the workplace — both your boss and coworkers have their own issues to deal with.
However, if the problem is urgent or serious, be sure to seek help to solve it as soon as possible. Don’t be afraid of being scolded. If there is a problem, the consequences may be more serious.
10. Use new technology with caution
I don’t deny that new technology is a good thing, but when using it, if you are not 100 percent sure, you will probably die. If something does go wrong and you can’t fix it yourself, there will be irreparable damage.
Therefore, after receiving the project, do not rush to start writing code, to think first, when the needs of the chest, do have a clear idea of the work of each plate, then start to write, more efficient, and the probability of error is lower.