Saturday, September 12, 2009

Why Bother with Coding Standards?


Coding standards can be annoying but they serve a good purpose. If everyone in a project adheres to the same coding standard guidelines it's much easier to dive into the code and get things done. If coding standards are not in place it may take longer to understand what the programmer is trying to do. This comes into play especially for developers who are just joining the project.

Another aspect of why coding standards are good is because it's easier to spot bugs if the style is in line with the rest of the project. Documentation generators like JDOC and Doxygen provide a really good reason to enforce coding standards since those tools are used to provide other developers easier access for helping the project grow.

For the Robocode project I choose 3 guidelines to follow:

Robocode Guidelines overrides the prior two, as does ICS-SE Coding Standards to The Elements of Java Style. A really useful tool that helps with formatting code is distributing an xml file that contains formatting rules and importing that into Eclipse IDE. If everyone uses this file to format their document, it saves a lot of trouble and awkward situations where a member would have to confront the other person because they were using 4 space tabs instead of 2. No one really wants to be this picky so it helps for the IDE to do it automatically.

Here's an example of what a format file looks like:


<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>

<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>


Once you have imported the projects Eclipse XML formatting file, you simply select Format from the Source menu.

I have updated my Robocode Sample bots according to the standards:

0 comments:

Post a Comment