Code neat way - on identifiers

title: Code tidy way - on identifiers

blog: CSDN

the Data: the Java learning routes and Video

Software name everywhere. We gave variables, functions, parameters, classes and packages named. We give the source code and source code directory named. Named so much to do, you might do it. Below lists a few simple rules of a good name.

  • Worthy of the name, see the name EENOW
    • Variable names too casual, haha, list1, ok, theList these lacks significance
  • Avoid misleading
    • It contains List, import, java and other class name, keyword or special characters;
    • And the letter o numbers 0, 1, etc. and digital letter l
    • Beware of using the difference between the smaller names. For example: XYZControllerForEfficientHandlingOfStrings and XYZControllerForEfficientStorageOfStrings
  • Do meaningful distinction
    • Negative example, the variable name: a1, a2, a3
    • Avoid redundancy, do not appear Variable, table fields to avoid table, string avoid nameString, direct name on the line, knowing that the string type
    • It defines two categories: Customer class and CustomerObject class, how to distinguish?
    • It defines three methods: getActiveAccount (), getActiveAccounts (), getActiveAccountInfo (), how to distinguish?
  • Use read out the name
    • Do not use a patchwork out of their own words, such as: xsxm (student's name); genymdhms (creation date, year, month, day, hour, minute, second) so-called hump nomenclature, try to use the full word
  • Use name searchable
    • Some constants, it is best not to directly use the number, and specify a variable name, variable name can facilitate the search.
    • For example: looking for MAX_CLASSES_PER_STUDENT easy, but looking for the number 7 on the trouble.
  • Avoid using coding
    • That variable name indicates that the variable data type lowercase letters start. For example, szCmdLine sz prefix means "zero-terminated string."
    • Avoid using a prefix, but Android in a better prefer represented by m and other private, personal feeling better
    • I do not like to use the interface to begin with, but also hope to achieve in the back to add Imp
  • Avoid thinking maps
    • For example conventional single letter do conventionally loop counter. So do not give some non-counter variable named: i, j, k, etc.
  • The class name
    • Class name and the object name should be nouns and noun phrases. The Customer, WikiPage, Account and AddressParser. Avoid using Data or class names such as Info. Not the verb. For example: Manage, Process
  • Method name
    • Method names should be a verb or verb phrase. As postPayment, deletePage save or
  • Do not play cute
    • Some variable called haha, banan not use eatMyShorts () represents abort ()
  • Each concept corresponds to one word
    • Simultaneous controllers and project managers, why not use one uniform? For those who will use your code a programmer, a consistent nomenclature is simply heaven gospel.
  • Do not use puns
    • Sometimes it may not be appropriate to use add, the proportion insert, append. add represents a whole new meaning added.
  • Use solutions Name
    • Look at the code are a programmer, so try to use those scientific terms, the algorithm name, model name, computer mathematical terms, according to the implications of named areas is not wise.
  • Use the field name from the implications of the
    • If they can not come to terms with a name familiar to programmers work at hand, on the use of at least, is responsible for maintaining the code programmers will be able to consult experts in the field comes from the name of the implications of the field.
  • Add meaningful context
    • Can be related variables into a class, use this class to show context.
  • Do not add useless context
    • The acronym name in with the project, so there is no need. For example, there is a "gas station Deluxe Edition" (Gas Station Deluxe) project called, in which each class GSD to add the prefix is ​​not a good strategy.
  • Last words
    • The hardest place to take a good name that describes the need for good skills and shared cultural background.

Epilogue

8qXr3n.png

2020-3-25: On the Java language environment to build -JDK8

2020-3-25: 2000 words read Java source

Guess you like

Origin www.cnblogs.com/bencoper/p/12573707.html