Code clean way (a): Part Name

Proportional to its cleanliness code quality. Clean code, both more reliable in terms of quality, but also laid a good foundation for the post-maintenance, upgrade.

Meaningful naming

  1. A real variable naming, to be able to see to know the name of justice; function name should be able to reflect the meaning of the whole function. Okay long name to the short name. Long name to highlight the more general meaning of the variable. And easier to search, easier to understand. Unless such variables have the obvious function of temporary and others have given their plain meaning. sum、temp

  2. Avoid misleading Avoid words in particular have some meaning in the computer industry with the use of some special significance: such as hp, ubuntu, dos, table and so on. While avoiding having the same or similar variable name in the code: the case for example with a different word or join the underlining will bring misunderstanding. Of course, not to say that local variables of the two functions can not take the same or similar names. As far as possible to avoid misunderstandings.

  3. Make meaningful distinctions such as: This is pointless function named because the programmer can not know how to call. getActivateAccount();getActivateAccounts();getActivateAccountInfo();

  4. Use read out the names not free coinage, and do not arbitrarily be abbreviated. Unless it is certain proprietary abbreviations can be found directly in the dictionary, or can not use. Unified English, do not use Hanyu Pinyin instead.

  5. Avoid thinking maps for commonly used variable names should comply with certain program segment specification. For example, i, j, k etc. for loop common language. However, in most cases, do not use single-letter names. Also special attention not to use o l or letters and the like is difficult to distinguish the 0 and 1.

  6. Class name class name and the object name should be a noun or noun phrase should not be a verb.

  7. Method Name Method name and function name should be a verb or verb phrase.

  8. Avoid puns follow the principles of the word a meaning.

  9. Add meaningful context

Guess you like

Origin www.cnblogs.com/harrypotterjackson/p/11431812.html