A while ago we decided on my team that we needed to increase our code quality. We were excited about that and thrilled to get it started with.
Then we looked at each other eyes, saw the passion to write better code but… something was missing!
When you think about it – how do you write better code? how do you increase your code quality?
With the help of the great people on StackOverflow, I managed to gather a list of principles that can take your code to the next level:
Learn how and write write write tests! you don’t have to go for TDD, but remember to test your code and make sure it runs as it is expected to before it leaves the dev environment. Tests include unit and regression tests.
You can use NUnit, TypeMock for .Net languages or other testing frameworks (every language has some).
Allow other developers to go through your code before you’re done with it; You and them will learn from that.
There are tools to help you with the code review process like Crucible.
I must say it’s magic! we implemented that on our team immediately (no tools currently, we just sit with each other) and several bugs have already been prevented because of that in only a few weeks!
Agree on coding standards and stick with them. This will help you understand other developers' code, reduce different code blocks that handle for the same issues and prevent bugs eventually.
- Coding standards – naming conventions for example.
- Exception handling standards – how to handle exceptions throughout the application.
- Logging standards - how and when to write log entries.
- Whatever you and your team decides on.
You can enforce standards with third party tools like: FxCop, StyleCop or Code Style Enforcer.
Use Tools to Help you Code Better
Design before you start coding and get your design reviewed before implementing it.
Read Related Books
Like Code Complete: A Practical Handbook of Software Construction or other books.
Talk and Meet with your Team
Talking makes wonders. Talk with your colleagues frequently and schedule a weekly meeting where every developer presents one interesting or important piece of code he/she have written during the week.
- Try to simplify the problem as much as you can.
- Try to break the code into small and well defined functional units (folders, files, namespaces, classes, methods) to keep the codebase logically organized and well structured.
- Document the code. Document it so your colleagues will understand it without your help.
Work with a source control system like SubVersion, CVS, Git, Team System or others.
Learn Other Languages
Even if those languages are not appropriate for your production code, you can find ideas in them and you can build your own internal tools with those languages.
My recommendation - learn IronRuby!
Own a Build Machine
A continous integration machine which automates the build process is a life saver. It can automatically build the application after every commit (or whenever you tell it to), run unit tests and create a setup project that people can immidiately go and install. It saves so much time! it also saves you from hitting your head against the wall when doing these repeating tasks youself.
Look here for a list of continuos integration applications.
I liked what Mark has written so I'm going to finish with that: "Quality is Free -- quality is conformance to specification and is built-in, not bolted on".
All the best,