Home > Article > Backend Development > Looking for bad code smells in the project (naming) Project industry code list Project discipline and code Javaee project source code
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 problems and where there are "bad smells".
Take your time and recall the code slowly. Start catching bad smells.
Things we often do and think about
Obscure if conditions
1) Processing of ||
Get up and spend more time
While reducing the number of lines of code is a good goal, minimizing the time it takes to understand the code is an even better goal. Return valueThe "$ret" above is an excuse for "I can't think of a name". Rather than using such an empty name, choose a name that describes the value or purpose of the entity.
$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.
Temporary variables
The $i here is "my temporary variable", which 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".
Loop iterator
I also found bad smell in my js code.
i Variable names are very generic, so don’t do them.
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 something else, it would be 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
If we spend a few more seconds to come up with a good name during the coding process, you will find that our "naming ability" will quickly improve.
I usually think of Chinese names 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.
Give me a gift of a nice name I saw recently
Original link: http://www.cnblogs.com/baochuan/archive/2012/07/12/2588317.html
The above introduces the bad smell (naming) of looking for code in the project, including the project and code aspects. I hope it will be helpful to friends who are interested in PHP tutorials.