Introduction
I have been working on projects during this period, so I have been relatively busy. Today I finally have time to go back and take a good look at the code I wrote to see where there are any problems. , where is the "bad smell".
Go slowly and recall the code slowly. Start catching bad smells.
Things you often do and think about
Obscure if condition
1) Processing of ||
alt="" src= "http://www.bkjia.com/uploadfile/2013/0904/20130904095420978.png" />The above code takes more time to understand than the following code
While reducing the number of lines of code is a good goal, minimizing the time required to understand the code is an even better goal.498)this. style="max-width:90%" onmousewheel="javascript: return big(this)" alt="" src="http://www.bkjia.com/uploadfile/2013/%200904/20130904095420376.png">
498)this. style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" src="http://www.bkjia.com/uploadfile/2013/0904/20130904095420978.png">The "$ret" above is "I can't figure it out Name" excuse. Rather than using such an empty name, choose a name that describes the value or purpose of the entity.
498)this. style="max-width:90%" onmousewheel="javascript: return big(this)" alt="" src="http://www.%20bkjia.com/uploadfile/2013/0904/20130904095420978.png">$alias declares that this variable is used to carry aliases - 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.498)this. style="max-width:90%" onmousewheel="javascript: return big(this)" alt="" src="http://www.bkjia.com/uploadfile/2013/%200904/20130904095422796.png">
498)this. style="max-width:90%" onmousewheel="javascript: return big(this)" alt="" src="http://www.bkjia.com/uploadfile/2013/0904/20130904095420978.png"> $i here is "my temporary variable", It is specially used to automatically increase statistical data and avoid duplication of statistical points. But the most important thing about $i is not the temporary variable. Use charset_index to represent "the subscript of my statistical data", which is more "descriptive".
Names like i, j, iter and it are commonly used as indexes and loop iterators. Although the name is vague, everyone knows that they mean "I am an iterator". - Actually if you use these names to mean other things, it will be very confusing. So don't do it.
If you insist on using vague names like i, j, it, then you must have a good reason to convince yourself.
Summary
When we are coding, spend a few more seconds to come up with a good name, and you will find that our "Naming ability" quickly improved.
I usually think of the Chinese name first. If I really can’t think of the corresponding English name, I will use a translation tool to paste the Chinese name that comes to mind, and then cut out the named variable or function name.
Gift a nice name I saw recently