Coding Conventions and Naming Standards C# and SQL Server

Introduction

In the world of software development, writing clean and maintainable code is not just good practice but it’s an essential requirement for building successful applications. One of the key factors that contribute to well-organized code is adopting coding conventions and naming standards.

In this blog, I’m going to share coding conventions that I adopted. It may help someone who wants to adopt rules for themselves or their team. Although coding conventions are not set in stone, and different teams may adopt different variations.

C# Rules

  • Always name variables as camelCase. For instance, userName, age, and isAuthorized.
  • Always name classes and their properties with PascalCase. For example:
 private class Customer {
   public string? FirstName { get; set; }
   public string? LastName { get; set; }
   public string? LoyaltyPoints { get; set; }
 }
  • Always name methods with PascalCase. This promotes consistency throughout the codebase.
  • Always name method parameters with camelCase. For instance:
public string FullName(string? firstName, string? lastName) {
  return $"{firstName} {lastName}";
}
  • Always use null checks (where applicable) to prevent compile-time warnings and runtime null reference errors.
  • Always add comments for complex or confusing code.
  • Use the async-await approach. Asynchronous programming with async-await has become essential in modern C# development, particularly when working with APIs. It allows the application to handle multiple requests efficiently and enhances responsiveness.

SQL Server Rules

  • Always name DB Tables and their columns in PascalCase. It enhances the readability of the database schema.
  • Always name the Database in PascalCase.

GitHub

  • Always name the GitHub repository in PascalCase.

Conclusion

In conclusion, adhering to coding conventions and naming standards in C# and SQL Server development is not just a matter of personal preference; it significantly impacts the overall quality of your code. Following these best practices makes the codebase more readable, consistent, and maintainable.

0
An error has occurred. This application may no longer respond until reloaded. Reload x