Naming convention is the most important part of standard  coding convention. By following a common standard to name identifiers, a common  medium of communication is established between the developers. Identifiers are  easily recognizable along with their context if a developer knows the standard.  Naming convention deals with naming almost every programming objects starting  from basic variables to large structures as classes and namespaces.
Before listing the standards, it is necessary to understand  three basic terms used in this context:
Pascal case
The first letter of each word in the name is in uppercase  and the rest of the word in lowercase. If a name consists of more than one  word, the first letter of each distinct word should be in uppercase. 
For example: BlackColorCode
This name constitutes of three words ‘black’, ‘color’ and ‘code’, hence their  first letters ‘B’, ‘C’ and ‘C’ are in uppercase respectively.
Camel case
All letters of the first word in the name is in lowercase.  If a name consists of more than one word, the first letter of each distinct  word (except the first word) should be in uppercase.
For example: blackColorCode
This name constitutes of two words ‘black’, ‘color’ and ‘code’. All letters of first  word ‘black’ is in lowercase. However the following words (in this case ‘color’  and ‘code’) have their first letters, both ‘C’, in uppercase.
Hungarian notation
Hungarian notion is a notation used to name objects by  prefixing their type in the name.
For example: strBlackColorCode
It identifies the variable as a string type, where ‘str’ is an abbreviation  used for string type. With typed languages like C#, Microsoft has chosen to get  rid of Hungarian notation and so shall we. We will use Hungarian notations  sparingly (almost try not to use at all).
Naming convention
In the table below, let us have a look at how to name various  programming units in C#. The first column has the programming unit, the second  has the details about which case to be used (and special conditions, if any)  and last column has an example to illustrate.
| Identifier  |     Convention | 
|---|---|
| Namespace | 
  |      
| Class | 
  |      
| Interface | 
  |      
| Enumerator  (Type and Values)  |     
  |      
| Property | 
  |      
| Variable | 
  |      
| Constant | 
  |      
| Method | 
  |      
| Parameter | 
  |      
| Event | 
  |      
| Attribute | 
  |      
Besides the standards mentioned in the chart above, the following should be taken care of:
- Do not declare two identifiers with same name only differing in case.
 - Name an identifier according to its meaning not its type.
 - Always add “EventHandler“ to delegates related  to events and “Callback” to delegates related to callback methods. 
 





0 comments:
Post a Comment