Naming conventions are a set of rules which are used to define different identifiers such as constants, variables, functions, etc. in a programming language.
Naming conventions are important for the following reason –
- They help a user to understand the meaning of code easily.
- It helps the code reviewers to focus on the important aspects of the code.
- To provide more information about the identifier such as what is that identifier for, etc.
- To provide clarity for potential ambiguity.
- To maintain consistency between the development team.
- To provide better understandability in the case where the code is used after a long period of time.
Some of the common things to be kept in mind such as -
- Length of identifiers – While defining identifiers it should be kept in mind that the length should be small because it is easy to type, extremely small identifiers (such as i or j) can be used for defining the inner part of a code such as inner loops. The longer identifiers may not be favoured because of visual clutter.
- Letter case numerals – Some naming conventions limit the use of letters either in upper case or in lower case. While some restrict on using numbers as the beginning of an identifier or specify some sequence to use letters, numbers, special characters.
- Multiple word identifiers – It is very important to use meaningful identifiers. Sometimes a single word identifier may not produce any meaning or may not be specific, so it is recommended to use multiple-word identifier so that the meaning should be clear such as (Why it is used for? Or For what it is used?).
- Delimiter separated words – In order to use multiple-word identifiers, we can use a delimiter such as a hyphen ( - ) or underscore ( _ ). For example, to represent a constant for exception constant we can write EXCEPTION_CONSTANT OR EXCEPTION-CONSTANT.
- Letter case separated word – This usually refers to the use of camel casing while defining an identifier. For example to write exception constant we can write it as ExceptionConstant or exceptionConstant. This is generally used in PASCAL, JAVA, C# and Visual Basic.