Refactoring: naming

Source: Internet
Author: User

Currently, during the reconstruction of a project, the following types of problems exist in the function and method naming:

 

1. It is a type of dog meat ". This type is the most hated type, which not only does not show the intention, but also has a misleading effect. For example, if the getXXX function returns an alloc or new object, the caller will not release the object after use, thus causing memory leakage.

 

2 "fuzzy ". Naming is a commonly used word for graph convenience. For example, if you get some properties, you can use Info directly, and the Custom control uses Custom. This does reflect some meanings, but it is not clear or in place. In addition, once these words are used, they will not be available when there is a more appropriate opportunity to appear.

 

3 "possession ". Once there is a custom class or UI control, add My in front. For example, MyLabel and MyDelegate. On the one hand, the class intention cannot be clearly expressed, and on the other hand, My is a one-time resource. If you want to customize a Label after MyLabel, is it in the dilemma of naming MyLabel2 or MyLabelEx?

 

4 "ID ". This is often encountered when reading the UI code. A single interface may have several labels. If you don't want to name it, you can name it lable1, lable2, lable3 ....... Although the serial number has strong scalability, its meaning is relatively vague.

 

5. "One-word multi-meaning ". A word has different meanings in different scenarios, such as ctrl. In some cases, control is used. In some cases, View controller is used. In some cases, it is used to indicate that the background model displayed for control is the verb meaning of control ). Although it is possible to identify its meaning after a bit of thinking and a pause, such inconsistency affects code standardization, readability, and maintenance.

 

6 ". The most notorious one is temp, which can be used under any circumstances. It can be called a universal variable name. This is no different from the "Comrades" and "classmates" of more than a decade ago. When I shouted back, I lost the meaning of my name. Another scenario is to name the name based on the scenario used for the first time, and then borrow it by the way, so that the name cannot match the actual name.

 

......

More types are expected to be discovered and addressed.

This article is from the "Lin Jia boys" blog, please be sure to keep this source http://bj007.blog.51cto.com/1701577/588073

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.