I have been working on projects for a long time, so I am relatively busy. today I finally have time to look back at my own code to see where there is a problem, where there is a bad taste, what I often do and what I often think.
Obscure if condition
1) Processing |
The above code takes more time to understand than the following code
Although reducing the number of lines of code is a good goal, it is a better goal to minimize the time required to understand the code.
Return value
The above "$ ret" is the toast of "I can't think of a name. Instead of using such an empty name, it is better to pick a name that can describe the object value or purpose.
$ Alias declares that this variable is used to carry the alias-indicating the purpose of this variable. And may help us find defects.
A good name should describe the purpose of the variable or the value it carries.
Temporary variable
Here, $ I is "my temporary variables", which is used to automatically increase the statistical data and avoid repeated statistical points. But for $ I, the most important thing is not a temporary variable. Use charset_index to indicate the subscript of my statistics, which is more descriptive ".
Loop iterator
I also found bad taste in my js code.
I variable names are very vague, so do not do this.
Such names as I, j, iter, and it are often used as index and loop iterator. Although the name is vague, everyone knows that they mean "I am an iterator". -- In fact, it will be confusing if you use these names to express other meanings. So do not do this.
If you have to use an empty name like I, j, and it, you have to have a good reason to convince yourself.
Summary
During the coding process, we will take several seconds to come up with a good name. you will find that our "naming capability" is quickly improved.
Generally, I want to give a Chinese name first. if I can't find the corresponding English name, I will use the translation tool to paste the desired Chinese name and then crop the name variable or function name.
Give me a nice name recently.