Coding Guidelines For A Developer

When we write code, it should follow some standard, which will improve the optimization, readability and quick action on the code, which also improves the security aspects of the code.

Follow the things given below.

  1. Naming convention
  2. Check for null
  3. Removed unused using’s
  4. Spacing
  5. Comment
  6. Code re-usability
  7. Project warnings

Naming convention

Pascal Casing: First characters of all words are upper case and other characters are lower case. Use PascalCasing for the class names and the method names. 

  1. public class InfoCoutureActivity {  
  2.     public void SocialActivity() {  
  3.         //…  
  4.     }  
  5.     public void ProgrammingActivity() {  
  6.         //…  
  7.     }  
  8. }   

Camel Casing

First characters of all the words, except the first word are upper case and other characters are lower case. Use camelCasing for the method arguments and the local variables. 

  1. public class EmployeeLog {  
  2.     public void Add(LogEvent logEvent) {  
  3.         int itemCount = logEvent.Items.Count;  
  4.         // …  
  5.     }  
  6. }  

For more details, visit here.

Check for null

Wherever null occurrence is possible, make an explicit null check, which avoids the execution error. 

  1. public string GetUserProfile(string userId) {  
  2.     if (userId != null) {  
  3.         //  
  4.     }  
  5. }   

Removed Unused Usings

Using statement will load all the assemblies, so it’s better to remove the unwanted assembly namespace reference in the codes.

Spacing

It is recommended to use TAB space rather than a white space and this helps for better code readability. Use single space between two lines of codes and the two lines between the methods.

Comment

It is always good to use the comments lines for each class, method and some logic which is too complex for a reader to understand.

Code re-usability

Try to use the available code and use the concepts like generics to avoid the repetitive codes. Code re-usability is the art of using an existing code to achieve better productivity and ease of maintenance.

Project warnings

Always avoid the project warning, which will help hackers to find a path to get into your code and break the applications.

Ebook Download
View all
Learn
View all