For any developer, Naming Conventions is a best practice when working on any development project. Let’s discuss more about Naming Conventions in this article.
Why Naming Conventions?
Naming Conventions are very important to identify the usage and purpose of a class or a method and to identify the type of variable and arguments.
Types of Naming Conventions
Below are the two major parts of Naming Conventions.
- Pascal Casing (PascalCasing)
- Camel Casing (camelCasing)
Pascal Casing (PascalCasing)
Use PascalCasing for class names, method/function names, and constants or read-only variables.
-
- public class Products {
-
- public
- const string ProductType = "General";
-
- public void GetProductDetails() {
-
- }
- }
Camel Casing (camelCasing)
Use camelCasing for variable names and method arguments.
- public class Products {
- public
- const string ProductType = "General";
-
- public void GetProduct(int productCategory) {
-
- int productCount;
-
- }
- }
Below are the best practices to follow in your projects. Do not use Hungarian notation or any other type of identification.
-
- string userName;
- int counter;
-
- string strUserName;
- int iCounter;
Prefix “I” letter for any Interface.
- public interface IProduct {
-
- }
Do not use underscores (_) in between words in variables.
-
- string userName;
- string departmentName;
-
- string user_Name;
- string department_Name;
Avoid using abbreviations for variable names.
-
- string departmentName;
- string employeeName;
-
- string deptName;
- string empName;
Use undersocre (_) as prefix for private static or global variables.
- public class Products {
-
- private static string _productGroup = "Packed";
- public List < Product > _products;
- public void GetProduct(int productCategory) {
-
- }
- }
Hope this helps you with your projects.
Happy Coding.