I. Naming
The naming scheme is the most influential help for understanding the logical flow of an application. The name should indicate "what" rather than "how ". By avoiding the name of the public basic implementation (which may change), you can retain the abstract layer that simplifies the complexity. For example, you can use GetNextStudent () instead of GetNextArrayElement ().
Naming principles:
Selecting the correct name may indicate the purpose of further analysis or definition. Make the name long enough to make sense, and be short enough to avoid being too long. The unique name is only used to differentiate items. Strong performance names are used to help people read; therefore, names that people can understand are meaningful. However, make sure that the selected name complies with the rules and standards of the applicable language.
The following are recommended naming methods.
1. Methods, attributes, and variable specifications
· Avoid obscure names that are easily explained by subjective interpretations, such as the aspect name AnalyzeThis () or the attribute name xxK8. Such a name may result in ambiguity.
· In object-oriented languages, it is redundant to include class names in Class Attribute names, such as Book. BookTitle. Instead, use Book. Title.
· Use the verb-Noun method to name the routines that perform specific operations on a given object, such as CalculateInvoiceTotal ().
· In languages that allow function overloading, all overloading should execute similar functions.
· If appropriate, add the computing qualifier (Avg, Sum, Min, Max, Index) at the end or at the beginning of the variable name ).
· Use complementary pairs in variable names, such as min/max, begin/end, and open/close.
· Since most names are constructed by concatenating several words, use a mix of upper and lower cases to simplify their reading. In addition, to help distinguish between variables and routines, use CalculateInvoiceTotal for the routine name. the first letter of each word is in uppercase. For variable names, use camel case sensitivity (documentFormatType). The first letter of each word except the first word is capitalized.
· The Boolean variable name should contain Is, which means Yes/No or True/False values, such as fileIsFound.
· Avoid using Terminologies such as Flag when naming state variables. A state variable has more than two possible values than a Boolean variable. Instead of using documentFlag, use a more descriptive name, such as documentFormatType.
(This item is for reference only)
· Even for variables that may only have a short lifetime in several lines of code, meaningful names are still used. Only use single-letter variable names for short-cycle indexes, such as I or j.