Home > Articles > Programming

  • Print
  • + Share This
This chapter is from the book

Coding Standards

Coding standards have long been recognized as a best practice when developing software. These rules apply to most languages and cover several aspects of coding. The overall purpose of coding standards is to produce software that has a consistent style, independent of the author. This, in turn, results in software that is easier to understand and maintain.

In most cases these standards are documented and formalized as part of company's technique of developing software. We can separate coding standards into various categories:

  • Mandatory—Those standards to be adhered to by all team members.

  • Guidelines—Those considered best or good practice and often describe the general approach toward development.

  • Recommendations—These rules are considered good practice and should be used at all times unless there are exceptional circumstances where valid justification can be given.

If you're using XP you will be developing in pairs, each taking turns and at the keyboard. Before coding starts, you will need an agreed upon set of rules on how to attack development. This removes petty arguments about formatting, naming, and such. Without coding standards the swapping of pairs would become difficult because you'd be forced to learn every other developers style and approach.

So, coding standards are not just a best practice—they grease the wheels of the development team and ensure that everybody wins.

Aspects of Coding Standards

There are a number of different aspects that coding standards seek to define, some of the key ones are listed in Table 6.4.

Table 6.4 Types of Coding Standards

Standard

Description

Formatting

Formatting includes the use of white space, indention, and length of statement lines in code. Some standards might include, for example, common editor setup and handling for tabs versus spaces for indentation.

Code structure

Code structure includes overall project layout (files, and so on), classes, resources, and other source file types.

Naming conventions

Naming conventions specify how developers name their methods, classes, variables, events, and parameters.

Error handling

Error handling describes how objects handle errors, reporting, and logging

Comments

Comments are an English description in the code that explains the logic of the code. (Quality code should be self-documenting by default.) The use of quality commenting gives quality code better maintainability and easier understandability.


Where to Go for Coding Standards

If you want a head start on creating your own coding standards a good place to start is the relevant development communities. Both Microsoft and Sun offer their own versions of coding standards. Other vendors, such as Borland and IBM will have their own guidelines for effective development. That's not to say that Microsoft's coding standard is any better than yours is; the important thing is to have a standard and then conform to it. To help you in defining your own standards we've included links to the Sun Java and Microsoft .NET coding standards in Table 6.5.

Table 6.5 Coding Standard References

Coding Standard Web Link

Java

http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

Microsoft .NET

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsent7/html/vxconcodingstandardscodereviews.asp


A good practice to use when applying coding standards to your project is to create just-in-time standards. With just-in-time standards you decide on standards and guidelines, as you need them. Using a tool such as Wiki Wiki (a Web-based collaboration application) developers agree on naming conventions and so forth as the need arises. The principle with this approach is that if no standard exists for your task quickly convene an on-the-fly meeting and agree on one together. When the standard is agreed to, add it to your Wiki Wiki site for the project.

NOTE

An on-the-fly meeting is where developers spin their chairs around in a circle or gather at the whiteboard. XP has the entire team sitting in the same work area, so this is practical.

  • + Share This
  • 🔖 Save To Your Account