Find bad naming of code in your project_PHP Tutorial

WBOY
Release: 2016-07-21 15:17:47
Original
808 people have browsed it

Things you often do and think about

Obscure if condition

1) Processing of ||

                                                                                                             

 

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.

Return value

                                                                                                                                                                                                                                                                                                   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 variable

The $ i here is "my temporary variable", which is specifically used to increase the statistical data automatically 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 name is very empty, so don't do it.

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

When we are coding, if we spend a few more seconds to come up with a good name, you will find that our "naming ability" will quickly improve.

I usually think of a Chinese name first. If I really can’t think of a 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 with a nice name I saw recently

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325648.htmlTechArticleThings that are often done and often thought about. Obscure if conditions 1) For the processing of ||, the above code is better than The code below takes longer to understand. Although reducing the number of lines of code is a good goal,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template