GST Billing Software

header image

Naming Conventions

Erachana Line

1. Do use PascalCasing for class names and method names:

public class ClientActivity

{

public void ClearStatistics()

{

//...

}

public void CalculateStatistics()

{

//...

}

}

2. Do use camelCasing for method arguments and local variables:

    public class UserLog
    {
                   public void Add(LogEvent logEvent)
                   {
                                  int itemCount = logEvent.Items.Count;
                                  // ...
                                  
                   }
   }

3. Do not use Hungarian notation or any other type identification in identifiers

    // Correct
    int counter;
    string name;    
    // Avoid
    int iCounter;
    string strName;

4. Do not use single character variable names like i, n, s etc. Use names like index, temp One exception in this case would be variables used for iterations in loops.

EX: for( inti=0; i<count; i++ )

{

…

}

If the variable is used only as a counter for iteration and is not used anywhere else in the loop.

5. Use meaningful names for variables.

EX: string address;

Decimal salary;

6. Avoid using Abbreviations. Exceptions: abbreviations commonly used as names, such as Id, Xml, Ftp, Uri.

                // Correct
                   UserGroup userGroup;
                   Assignment employeeAssignment;     
                   // Avoid
                   UserGroup usrGrp;
                   Assignment empAssignment; 
                   // Exceptions
                   CustomerId customerId;
                   XmlDocument xmlDocument;
                   FtpHelper ftpHelper;
                   UriPart uriPart;

7. Do not use Underscores in identifiers. Exception: you can prefix private static variables with an underscore:

               // Correct
                   public DateTime clientAppointment;
                   public TimeSpan timeLeft;    
                   // Avoid
                   public DateTime client_Appointment;
                   public TimeSpan time_Left; 
                   // Exception (Class field)
                 privateDateTime _registrationDate;

8. Do use predefined type names instead of system type names like Int16, Single, UInt64, etc

               // Correct
                string firstName;
                   int lastIndex;
                   bool isSaved;
                   // Avoid
                   String firstName;
                   Int32 lastIndex;
                   Boolean isSaved;

9. Do use implicit type var for local variable declarations. Exception: primitive types (int, string, double, etc) use predefined names.

                   var stream = File.Create(path);
                   var customers = new Dictionary();
                   // Exceptions
                   int index = 100;
                   string timeSheet;
                   bool isCompleted;

10. Do use noun or noun phrases to name a class.

                public class Employee
                   {
                   }
                   public class BusinessLocation
                   {
                   }
                   public class DocumentCollection
                   {
                   }

11. Do prefix interfaces with the letter I. Interface names are noun (phrases) or adjectives.

               public interface IShape
                  {
               }
                   public interface IShapeCollection
                   {
                   }
                public interface IGroupable
                   {
                   }

12. Do name source files according to their main classes. Exception: file names with partial classes reflect their source or purpose, e.g. designer, generated, etc.

                // Located in Task.cs
                   public partial class Task
                   {
                               //...
                   }
                // Located in Task.generated.cs
                   public partial class Task
                   {
                              //...
                   }

13. Do organize namespaces with a clearly defined structure:

               // Examples
                   namespace Company.Product.Module.SubModule
                   namespace Product.Module.Component
                   namespace Product.Layer.Module.Group

14. Do vertically align curly brackets:

                   // Correct
                   class Program
                  {
                                  static void Main(string[] args)
                                  {
                                  }
                 }

15. Do declare all member variables at the top of a class, with static variables at the very top.

               // Correct
               public class Account
                {
                               public static string BankName;
                               public static decimal Reserves;      
                               public string Number {get; set;}
                               public DateTime DateOpened {get; set;}
                               public DateTime DateClosed {get; set;}
                               public decimal Balance {get; set;}     
                               // Constructor
                               public Account()
                               {
                                                    // ...
                                  }
                }

16. Do use singular names for enums. Exception: bit field enums.

               // Correct
               public enum Color
               {              
                                Red,
                               Green,
                              Blue,
                              Yellow,
                               Magenta,
                               Cyan
               } 
    // Exception
    [Flags]
    public enum Dockings
    {
       None = 0,
       Top = 1,
       Right = 2, 
       Bottom = 4,
       Left = 8
    }

17. Do not explicitly specify a type of an enum or values of enums (except bit fields)

    // Don't
    public enum Direction : long
    {
      North = 1,
      East = 2,
      South = 3,
      West = 4
    } 
    // Correct
    public enum Direction
    {
       North,
       East,
       South,
       West
    }

18. Do not use an "Enum" suffix in enum type names.

               // Don't
                public enum CoinEnum
                  {
      Penny,
      Nickel,
      Dime,
      Quarter,
      Dollar
               } 
    // Correct
    public enum Coin
    {
       Penny,
       Nickel,
       Dime,
       Quarter,
       Dollar
    }

19. Do not use "Flag" or "Flags" suffixes in enum type names.

                 //Don't
                [Flags]
                  public enum DockingsFlags
               {
       None = 0,
      Top = 1,
      Right = 2, 
      Bottom = 4,
       Left = 8
               }
                //Correct
                 [Flags]
    public enum Dockings
    {
       None = 0,
       Top = 1,
       Right = 2, 
       Bottom = 4,
       Left = 8
    }               

20. Do use suffix EventArgs at creation of the new classes comprising the information on event:

                // Correct
               public void BarcodeReadEventArgs : System.EventArgs 

21. Do name event handlers (delegates used as types of events) with the "EventHandler" suffix, as shown in the following example:

    public delegate void ReadBarcodeEventHandler(object sender, ReadBarcodeEventArgs e);

22. Do not create names of parametres in methods (or constructors) which differ only the register:

               // Avoid
                private void MyFunction(string name, string Name)

23. DO use two parameters named sender and e in event handlers. The sender parameter represents the object that raised the event. The sender parameter is typically of type object, even if it is possible to employ a more specific type.

24. Do use suffix Exception at creation of the new classes comprising the information on exception:

               // Correct
                public void BarcodeReadException : System.Exception 

25. Do not use variable names that resemble keywords.

EX: string string=""; stringgoto=""; string class="";