Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼


Coding Conventions: Make Them Agile

1. Make Your Code Look Like Other People's Code

Nothing hurts readability and maintainability more than developers mixing and matching coding styles in a file. Think of the guy who's going to come on this project after you. Okay, you have a prettier way of implementing that event handler.... So what? Two years from now, other developers will read the code. They'll wrap their brains around the coding standards used in the files--until they come to yours, which will make them scratch their heads and waste time figuring it out. Your's will probably look like a mistake and be treated like a bug.

When you start on a new project, get the coding conventions document. Read it. Then forget it. Scroll through the file to see what style is actually used in the project and write your code like that.

If you feel like reformatting the existing code to suit your preferred coding style, refer to rule number 10.

2. Use the Simplest Design Possible

Don't try to be overly clever when you're solving a problem. Just find an easy solution and use that one. Ignore the temptation to craft a complex work of art that will amaze and dazzle your teammates.

This often happens when developers try to optimize prematurely. Developers think that this function is too slow and bloated, so they write some complex (and likely efficient/small) piece of code. It may be elegant code, but if the design or algorithm is too complex, no one will understand it, much less be able to maintain it.

This same point counts for developers who see a problem and want to invent a framework to solve the current problem and any similar problems in the future. Don't do it... yet. Unless you can see several good known examples where this framework will be used in a future sprint, you will only waste time and effort. Wait until you start working on the future problems before creating the framework and refactoring existing code. This can be done safely if you have good unit tests. You do have unit tests, right?

If you feel that you must write some insanely complicated, highly optimized, inline assembly code, refer to rule number 10.

3. Don't Re-invent the Wheel

Always use existing APIs and class libraries. Developers are sometimes tempted to show off their coding kung fu, but inventing a new way to sort only wastes time. Not only will you waste time solving a problem that's already been solved, you'll waste even more time fixing the new bugs your new "better" way introduces to the code base.

Existing APIs and class libraries have already been tested and documented. And everyone knows them, so when you use them, your application will be easier to maintain. An easy-to-maintain application is good news for your team, your client, and the person who will have to actually do the maintenance.

If you feel you must implement that overly complicated, but clever, linked list that saves 0.02% memory usage, refer to rule number 10.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.