Find the bad taste of code in the project (name)

Source: Internet
Author: User

Introduction

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 and see where there is a problem and where there is a "bad taste ".

Slowly, slowly recall the code. Start to capture bad taste.

What you often do and what you always want

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095419483.png"/>

Obscure if condition

1) Processing |

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095420518.png"/>

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095420978.png"/> the above Code takes more time to understand than the following code

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095420225.png"/>

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.

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095420376.png"/>

Return Value

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095421511.png"/>

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095420978.png"/> the above "$ ret" is the word "I don'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.

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095421331.png"/>

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095420978.png"/> $ alias declares that the variable is used to hold the alias-indicating the purpose of the variable. And may help us find defects.

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095421813.png"/>

A good name should describe the purpose of the variable or the value it carries.

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095422796.png"/>

Temporary Variable

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095422838.png"/>

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095420978.png"/> here $ I is "My temporary variables ", this function is used to automatically increase statistical data to avoid duplication of 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 ".

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095422626.png"/>

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095423790.png"/>

Loop iterator

I also found bad taste in my js Code.

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095423953.png"/>

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095420978.png"/> I variable name is very empty, so do not do this.

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095423531.png"/>

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.

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095424739.png"/>

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.

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = "\" src = "http://www.bkjia.com/uploadfile/2013/0904/20130904095424909.png"/>


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.