Simple Naming Conventions to Follow
To code clearly, one must use to indentify coding elements appropriate, precise names. Named appropriately and precisely, the names of coding elements provide to the reader clear, accurate information. With that information, the reader is able to understand more easily the code that he is perusing. Consequently, naming conventions that produce appropriate, precise names are essential for writing good code. As a means to achieve such names, the list below provides guidelines.
- The names of all interfaces and classes should begin with a capital letter. This convention is simply good, object-oriented form. Beginning classes and interfaces with a capital letter helps a reader to identify types.
- All interface names should begin with the letter “I.” This convention is borrowed from DotNet. The letter “I” provides a shorthanded, simple way to identify interfaces.
- Any class that is intended to be used as a base class should have in its name the word “base.” With “base” in the name, a reader knows that the designer intended a class to be used as a building -block. As a result, a reader can easily distinguish between building blocks and non-building-blocks.
- Any class that contains only static methods should have in its name the word “utility” or “library.” Such words signify to the coder that a class is intended to be used as a helper.
- The names of all methods and functions should begin with a lowercase letter. Similar to the first rule, this convention is simply good, object-oriented form. Such a convention assists a reader in distinguishing easily between classes and methods.
- All method names and function names should contain a verb. Including in the name a verb allows the reader to identify easily actions.
- All variable names and field names should begin with a lowercase letter. Similar to the first and fourth tips, this convention is simply good, object-oriented form. Such a convention helps a reader to distinguish easily between data and classes.
- All variable names and field names should contain, unless their type is Boolean, a noun. By including a noun in the name, a coder helps reader to identify easily data.
- Any variable name or field name whose data type is Boolean should be formulated as a question. Similar to the first, fourth, and sixth tips, this convention is simply good, object-oriented form. A coder who formulates Boolean data as a question helps a reader to distinguish easily between flags and data.
- The letters of any constant should be capital letters. This convention is simply good structured form. Making a constant’s letters capital allows a reader to distinguish between constants and everything else.