Find the Bad Name of the Code in the project

Source: Internet
Author: User

What you often do and what you always want

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.