总结应该遵循的编码、调试规则
I spend more than a week to debug a problem about program crash,feeling funstrated all the week until the day I finally solove the problem.
In order not to commit such kind of mistake, I write this article to summary the note point when I write code in the future and should obey the rule as much as possible.
- We should sort the whole thing with a clear flow chart before we write code. And we should check the flow chart before we examine our code, in order to check if we have some unexpected conditions
- check if we have a memory leak. Memory leak can cause some odd phenomenon
- Don't work complicate code
- especially when writing complicate code, we should pay attention to the return value of one function, also the reference manual.
- According to above ,we should always return proper value, and always validate the parameters, return the error code if not illegal , unless we really no need to.
- Use single thread instead of multi-thread as much as possible , cuz debugging multi-thread is very difficult. Passing parameters instead of global parameters.
- Keep a clear mind when we write and debug, instead of digging into the problem when feeling dizzy