3 Steps to Quality Code

We each have our own style and preferred way of coding. These preferences come from our experience and what feels right over time. As long as we’re the only developers working on a specific project this isn’t a problem. But what happens when you get five or ten developers all with their own preferred way of doing things working on the same project? Anarchy!

The only way to keep your sanity, and the sanity of those developers working with you, when working on projects is to take some basic steps to ensure that you are producing quality code that can be maintained and extended in the future.

1. Define Standards

Writing documentation is no fun! Nobody likes it, everybody hates it and we wish we could do without it. However, the only way that we can ensure everyone on our team is doing things the same way is to document a commonly agreed upon format/standard so everyone can follow along.

Before you spend a lot of time trying to come up with standards on your own, do some Google searches and take advantage of existing resources that are already available like the following:

Playbook standards by Thoughtbot

The playbook, written by thoughtbot, is a great resource for more than strictly code standards. With sections covering laptop setup, sales, production and more this is a great place to start your research.

Playbook standards by Thoughtbot

This open source collection of best practices and code standards for front-end development was put together by Isobar. With the source code avialable on GitHub this is a good template to start with.

Playbook standards by Thoughtbot

An oldie but a goodie, the coding standards released by WordPress are another source to reference when defining your own rules.

Playbook standards by Thoughtbot

Never one to be left out, Drupal has their own set of coding standards on their website you can reference also.

No need to reinvent the wheel here. You don’t have to use WordPress, Drupal or a specific framework to borrow from their standards. Popular open source tools help bring standardization and introduce best practices to the masses, which is ultimately what we’re trying to do.

2. Review Code

I think Smokey the Bear said it best “only you can prevent bad code.” Okay, that might not have been Smokey but it’s a true statement. Just because code has been written and “works” doesn’t mean it should be merged right in to production and deployed live with no additional oversight.

Code quality is every developers responsibility and code reviews give developers the opportunity to learn from each other and to ensure code is standards compliant before it’s pushed to production. By defining a review process and outlining how new code will be merged in to production you will create a good reliable pipline for continuous integration.

3. Leverage Existing Tools

Automation is your friend. Any opportunity you have to automate complex or annoying tasks should be explored fully. Lucky for us some tools have hit the market that help to automate parts of the quality assurance process:

Playbook standards by Thoughtbot

An automated code review service that supports Scala, JavaScript, Python, PHP and CSS.

Playbook standards by Thoughtbot

SensioLabs Insight
From the maintainers of the Symphone PHP framework comes a PHP specific tool that analyzes your code for security issues, bugs and performance.

Playbook standards by Thoughtbot

Code Climate
An automated code review service that supports Ruby, JavaScript, PHP (beta) and Python (beta).

Playbook standards by Thoughtbot

An automated code review service supporting the largest number of langauges including Python, Ruby, JavaScript, PHP, Go, Scala, Java, Haskell, etc.

It’s important to note that there is no silver bullet solution. While some of the tools above gloat about automating code review I still think it’s valuable to have humans involved in the code review process, even if it’s minimally. Human code reviews provide teachable moments where developers can learn from one another and make themselves, and not just the code, better.

It’s easy to overlook standards and code quality when you are just starting to develop a new application, especially if you are a solo developer. However, as the code base and team grows you will quickly see the issues and downsides that come with not laying down some ground rules early on. So decide on some standards, schedule some code reviews and investigate ways to automate parts of your QA process. Your application will thank you for it.

What tools or techniques do you use to ensure quality code on your development projects? Let me know by leaving a comment below.