Find the bad taste of code in the project (named) _php Tutorial

Source: Internet
Author: User
Introduction

This time has been doing the project, so relatively busy, today finally have time to look back to the code, see where there is a problem, where there is a "bad taste."

Slowly, slowly recall the code. Start catching the bad taste.

Something that is often done and often thought of.

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

Obscure if condition

1) for | | The 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 code above is going to take more time than the following code to understand.

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, minimizing the time required to understand the code is a better goal.

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/ The "$ret" above "/>" is 0904/20130904095420978.png "I can't think of a name". Instead of using such empty names, pick a name that describes the value or purpose of the entity.

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 this variable is used to host aliases-The purpose of this variable is indicated. And it could help us find a flaw.

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 is carrying.

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

Temp 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 variable ", specifically to let statistics automatically increase, to avoid the duplication of statistical points. But the most important thing for this $i is not temporary variables. Using Charset_index to represent "subscript for my statistics" 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 a 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 vague, so do not do so.

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

Names like I,j,iter and it are commonly used for indexing and looping iterators. Although the names are vague, everyone knows that they mean "I am an iterator". You actually use these names to express other meanings, which can be confusing. So don't do this.

If you have to use i,j,it such a vague name, then you 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 "/>

Summarize

In the process of coding, it takes a few seconds to come up with a good name, and you will find that our "naming ability" is quickly lifted up.

I usually first think of the Chinese name, if I can not think of the corresponding English name, I will use the translation tool to put the thought of Chinese paste up, and then to crop the name of the variable or function names.

Give me a nice name that I've seen recently.

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


http://www.bkjia.com/PHPjc/445677.html www.bkjia.com true http://www.bkjia.com/PHPjc/445677.html techarticle introduce this period of time has been doing the project, so relatively busy, today finally have time to go back to take a good look at their own code, see where there is a problem, where there is a bad taste. Slowly over ...

  • 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.