Wednesday, June 04, 2008

Setting Coding Practices

Let's face it, anyone that has worked in development for any length of time will know that there is always change, and the "quality" of the code is a key area where this change is seen.

When you start on a project, you're not too familiar with the technology, you're not familiar with the problem space and you have a lot to learn. So you code in a certain way, and you use particular techniques to achieve your goals in code. Over time you learn better techniques, but the problem is you don't retrofit your old code to use the new techniques.

Recently I had to work on code that was written right at the beginning of my current project. Wow! Was it legacy.

This change and development is a good thing in the sense that it is a sign that things are improving, however it presents a challenge in that developers are very good copy cats. They will typically do things the way they see them done (even if that way is wrong) and don't as a rule go against that. In a sense that is also a good thing because we don't want a group of cowboys all doing their own thing.

The challenge is how do we accept this change and improvement, allow for it and even encourage it, and at the same time communicate the best practice approach to doing things. Furthermore, at some point we need to limit improvements (there's always trade offs), because any change that is made, needs to be tested. In our code base we still have all the various ways that things have been done from the beginning until now. When you have a project that has been going for two years, this is inevitable.


Colin said...

It seems a bit pointless retrofitting old code - especially if it "ain't broke". How about indicating legacy code with @deprecated (or a custom "@legacy" annotation/Eclipse task tag) - pointing the developer to an example of the modern approach? If a developer mistakenly follows an example that has been marked "@legacy" then they should be required to redo it correctly.

mx said...

Good point, but then you still have the issue that the code is not fixed. If you don't fix those issues they're eventually going to bite you.