A software coding standard is a set of rules and guidelines for the formatting and organizing source code. Software coding standards are used to define a specific programming style.
In professional environments, the benefits of coding standards include readability, maintainability and compatibility. Any member of a development team needs to be able to quickly read and understand the code of another member. The developer who maintains a piece of code tomorrow may not be the developer who programmed it today. Many of today’s enterprise solutions are so complex that multiple development teams commonly unite to build a singular enterprise software application. With coding standards in place, disparate teams can rely on the way that they can interface with the code built by a separate team.
This blog will touch on a simple set of practical coding standards for the File Organization of a software program coded in C#, a fourth generation language commonly used by developers to develop desktop, mobile and web applications.
C# code should be written in files with the .cs suffix and have the format illustrated in the following sections
Using statements are used to define the assemblies that will be used by the file.
Name Space Definition
A Name Space is used to eliminate the possibility of a class collision, i.e. two code bases having a liked named class.
Used to describe the name of the class and optionally define the base class inherited from and/or interfaces implemented.
Preface with private access modifier and read only attribute. Capitalize all letters in constant.
Preface with private access level and add _ prefix to variable name. Variable name should not be capitalized.
Preface with public, protected or Internal access modifiers. Capitalize property name.
Preface with public access modifier. Name must equal name of class. May optionally contain one or more parameters.
Preface with appropriate access modifier and return type. Always decorate with function comment.
Preface with appropriate access modifier usually private and void return type. Always decorate with function comment.
Example C# File
While the benefits of Coding Standards include readability, maintainability and compatibility, the real benefit lies in the ability to unite disparate teams around set of rules and guidelines for the formatting and organizing source code. Knowing that the code built by one team will be interpreted as it was intended by a completed different team ensure a more fluid workflow from team to team.