Same Line or Next Line? Tabs or spaces? Camel case, underscores, or dashes? Whether the debate is code conventions or naming standards, most developers have their preference. Even if you don’t, you probably recognize these questions as falling under one of the most religious topics in software development.
Like most developers, I have my preference regarding conventions. I want my opening brackets on the same line. My file names? I can’t stand upper case letters, so give me dash-separated .jsp files. As for tabs, forget it; spaces are undoubtedly the way to go. While these are my preferences, I have one that’s even more important—standardization. Standardization applies to more than just syntax layout; it applies to names of classes, methods, and files, the organization of code, and commit messages. And yes, standardization includes coding conventions as well.
Have you ever stopped to consider why we have standards on a project? The most common argument for coding standards is that it helps others come up to speed on the code base more quickly. Consistent code is easier to read, but more importantly, it’s easier to maintain. On the surface, it would seem that modern IDEs make this argument almost moot. A few key strokes and the IDE will reformat your code. Instead, I would argue that modern IDEs make coding conventions absolutely painless to implement and comply with. Simply check a box and the IDE will reformat your code before it checks it into the code repository.
One of the benefits of coding standards is the minimalization of differences between file versions. This helps to reduce merge conflicts, and perhaps more importantly, helps developers to be able to understand changes to the code. By simply configuring the IDE to meet a standard coding convention and apply the standard on check-in, developers can significantly reduce the swirl associated code base changes caused by different formats.
Complying with naming and organization standards also can increase productivity. Project teams that consistently name their classes, organize their methods, and package their builds do not waste time wondering whether it’s the UserFactory, UserManager, or UserService that is needed to create a new User instance.
Finally, good coding conventions also can reduce bugs. Certain practices, such as allowing if blocks without brackets or assignments of multiple variables in one line, are error prone and difficult to identify. In these cases, coding conventions help to reel in the rouge coder who thinks these nuances are clever.
There are practical reasons for code base standards and I would like to suggest that if you’re ignoring them, you’re throwing away your development time. By adhering to standards, developers can help themselves and team members work more effectively.
About the Author
David DeWolf is the chief technical architect and founder of Three Pillar Software, Inc. He works with mid-sized and Fortune 1000 companies to establish corporate standards that promote best practices and agile development. David has over eight years of commercial software development experience and is a member of the Apache Software Foundation’s Struts, Tiles, and Portals projects. David actively participates in the Java Community Process as a member of the Java Portlet Specification Expert Group and is the author of various online publications.