Programming experience-avoid using Chinese pinyin for variable names

Source: Internet
Author: User

I have seen many people use Chinese pinyin as variable names, including used in databases, such as database names, table names, and field names, including in java/c #/c ++/javascript.

What is used as the variable name is harmless. Using Chinese pinyin as the variable name is much better than using Chinese characters as the variable name.

The problem is that in Chinese, there are too many homophone characters that can be converted from Chinese characters to pinyin, which is easy to understand and does not produce ambiguity. However, to let another person look at the variable names made of Chinese pinyin, he needs to convert pinyin into Chinese characters in his mind. Because of the large number of homophone characters, it may lead to difficulties in understanding or even misunderstanding.

 

Examples of homophone:

Fuji, attachment/fujian

Shanghai, shanghai, Shang Hai, and injury

Biaozhi, Logo/Peugeot/table store/bitch

BYD, BYD

BMW, BMW/touch me

Hanzi, Chinese character/man

Gangcai, just now/STEEL

Xinren, trust/New

It is not suitable for variable names.

Compared with full spelling in Chinese as a variable name, it is not desirable that many people use two or three initials to abbreviated them as a variable, which is more difficult to understand: because there are more Homophone Words.

 

For exampleGCThere are too many homophone words, which are in the Pinyin Input Method of ubuntu: just now/lyrics/STEEL/simple/high-rise/wrong/observed/just from/fault/glorious/gates/Public Beta/coffin/coexistence/Village/Public Toilet/licorice/worse/Collection /Village/pipe/Statement/Hence/National Quintessence/dried vegetables/national policy.

This is in Microsoft Pinyin in windows: high-rise/simple/just now/glorious/licorice/Hence/STEEL/lyrics/observation/Public Toilets/coexistence/fruit/resignation/collection/rolling/dry/confession/High ginseng/color/fault/ estimate/coffin/National Policy/ghostly/National Quintessence/lone/bone thorn/Hay/dried food/pass/pipe/follow/High talent/Word Formation/groove/strange talent/barn/light can/resignation/more times /fixed term/grain grass/change/attack error/cover vegetables.

 

As you can imagine, it is hard to determine what it means if a programmer sees the variable name abbreviated to GC pinyin.

 

I recommend that you always use English words as variable names. In many programming rules, variable names cannot be long. The problem is that if the variable name can be short, we will naturally get short ones, such as name; if the variable name is short, it will lead to ambiguity, then we have to use long names, for example, user_chinese_name and user_english_name.

This is not a simple rule: the variable name must be less than n characters.

 

In addition, variable names are long and there is no obvious disadvantage. The current development tool IDE provides the automatic prompt function for code input, and does not require many letters to be typed.

 

--------------------

Welcome to download the trial of the Single Sign-on system, http://zheguisoft.com

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.