Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Coding Standards and Conventions

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 242
    Comment on it

    Coding guidelines and Conventions

    1. Every object like datasets, class objects and other reference type variables must be declared with null assignment and must be set to null or Disposed if the object implements IDisposable interface, once they are done with their function.

    Example:-

     using(CustomValidation ObjCustomValidation =null)
        { 
            //Used the Object
        }
        OR 
        //declaration of Object 
          Private SendNotification _SendNotification  = null; 
        //Class level private variables name should start with underscore and Camel Case.
    
       try 
        { 
           //Used the Object 
          SendNotification = new SendNotification (); 
        } 
       catch(Exception ex) 
        { 
           //Handled exception
        } 
       finally
         {  
            //destroyed the Object
            if (SendNotification != null) { SendNotification .Dispose(); }
         }
    

    2.Comment on start and end of every loop is MUST. Example:--

        public static Control RecursiveFindControl(Control controlParent, string controlName) 
        //Method level variables name should be in Camel Case and without any underscore (_). 
        {
         Control controlReturn = null;
         //entering a loop that will find a control in the given control collection
         foreach(Control controlChild in controlParent.Controls) 
         { 
            if(controlChild.Name == controlName) 
            { 
                controlReturn = controlChild; 
                //found the control, Will go out of loop break; 
            } 
            else 
            { 
                controlReturn = RecursiveFindControl(controlChild, controlName); 
                if(controlReturn!= null) 
                //found the control, Will go out of loop break; 
            } 
          } 
        //out of loop return controlReturn; 
    }
    

    3.Code which is commented in new code should be removed, not left in the code. The code should simply be removed rather than commented. Not in use commented code block should be in region if it is required for reference, otherwise should be removed.

        public DataSet GetCustomerData(string Parameter) { try
        { 
            #region Code not in use 
            //another field discription is also required so SQL is changed 
            //string SQLString = Select CustomerID,Name from Customer Where + // Parameter; 
             #endregion Code not in use 
            string SQLString = Select CustomerID,Name, Discription from Providers Where + Parameter; 
            DataSet dataSetResult = SqlHelper.ExecuteDataset(ConnectionString,CommandType.Text, SQLString); 
                    dataSetResult.Tables[0].TableName="CustomerDetails"; 
            return dataSetResult;       
            }
    

    4.Exception must be handled using TRY CATCH blocks and nowhere in the code it should just catch it and do nothing. If exception is caught it must be handled to perform next action. i.e. We must try to do that exception causing action again or do it in some other way.

        try 
            {
              //When we try to open a non existent file we got FileNotfoundException 
          File.OpenRead("NonExistentFile"); 
             } 
            catch(FileNotFoundException fx) 
            { 
             //Here we can write a log for any errors 
            }
    

    5.Code indentation is very helpful and must be done carefully for your own help in debugging. For indentation, you can use Ctrl+K+D and it will indent the code automatically.


    6.Variables and objects MUST BE declared with complete names. Complete paths MUST BE used while qualifying objects.

    Example:--

    **System Defined Controls naming conventions** 
    Label controls = LabelFirstName 
    Editbox controls = EditboxFirstName 
    Button controls = ButtonSave 
    CheckBox controls = CheckboxSex 
    RadioButton controls = RadioButtonInterest
    Panel controls = PanelSalery 
    DataGrid controls = DataGridStudent 
    

    7.The following rules outline the guidelines for naming classes:
    --Use a noun or noun phrase to name a class.
    --Use Pascal case.
    --Use abbreviations sparingly.
    --Do not use a type prefix, such as C for class, on a class name. For example, use the class name FileStream rather than CFileStream.
    --Do not use the underscore character (_).
    Example:--

        public class FileStream 
        public class Student
        public class Employee
    

    8.The enumeration (Enum) value type inherits from the Enum Class. The following rules outline the naming guidelines for enumerations:


    --Use Pascal case for Enum types and value names.
    --Use abbreviations sparingly.
    --Do not use an Enum suffix on Enum type names.
    --Use a singular name for most Enum types, but use a plural name for Enum types that are bit fields..


    9.The following rules outline the naming guidelines for methods:
    --Use verbs or verb phrases to name methods.
    --Use Pascal case.

    Example:--

    The following are examples of correctly named methods. 
    RemoveAll() 
    GetCount() 
    Invoke()
    

    10.The following rules outline the naming guidelines for properties:
    --Use a noun or noun phrase to name properties. .
    --Use Pascal case. .
    --Do not use Hungarian notation. .
    --Consider creating a property with the same name as its underlying type..


    11.General variable & parameter naming conventions:--
    Parameter name = camelCasing
    Namespace = PascalCasing
    Interface = PascalCasing with I as prefix
    Type = PascalCasing
    Member Variable = PascalCasing
    Private member variables of Class should start with _ (underscore) and Camel Case
    Private member variables of Method should be Camel Case
    Public member variables of Class should be in Pascal Case


    12.Database Objects Naming Conventions--
    Database = Pascal Case eg ChinaTrade
    Table Name = Pascal Case Employee
    Primary Key = TableName_PK eg Employee_PK
    Foreign Key = ParentTableName_ChildTableName_FK eg Employee_EmployeeDetails_FK

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: