Discussions about writing clean code and ensuring quality comes up often within software engineering circles. This can be attributed to an increase in adoption of Agile techniques and issues related to technical debt (at many levels of development).
It’s an important problem that must be addressed and resolved efficiently as ignoring it can send you down a black hole of technical debt. Although most developers in an Agile environment will want to consistently write better code, ending up with bugs is always going to be inevitable.
So the best we can do is come up with processes that can be utilized to keep bugs in the code down to a minimum. But how do software development teams achieve this?
Taking Responsibility is Key
There are several different philosophies when it comes to maintaining quality code in an Agile environment. But for the most part, it all comes down to taking responsibility.
For example, according to Charles G. Cobb, author of “The Project Manager’s Guide to Mastering Agile,” the best way to ensure code quality is to make the development team take responsibility for the quality of the product they are working on.
After all, it’s the responsibility of the people who are coding, not someone else. Cobb also believes that it’s more effective and highly efficient to build quality into a product rather than relying on testing the finished product to identify and fix the bugs within it.
According to the author, having an independent Quality Assurance (QA) team will not be as effective as individual software engineers taking responsibility for their own work during the build cycle. Furthermore, enforcing quality standards from the outside can also end up being counter productive.
However, there are several counter-arguments that highlight the importance of QA teams. For example, some in the industry prefer software testers to work closely with developers (and all other stakeholders) right from the start.
This because their presence from the beginning of a scrum (and all those that follow) can help ensure that everyone is on the same page producing quality code (every step of the way). Another approach is to adopt software engineering best practices to minimize technical debt and write clean code.
Test-Driven Development (TDD)
Test-driven development or TDD is an evolutionary approach that embraces a programming style where the following activities are tightly interwoven:
- Testing (writing unit tests)
- Design (a form of refactoring)
This means that a developer will write a single unit test that describes an aspect of the program, run the test (which will fail as the program lacks that feature), and then write just enough code (as simple as possible) to allow the test to pass.
Next, the code will need to be refactored until it conforms to a principle of simplicity. Then you start accumulating by repeatedly running the unit tests over time.
Ron Jeffries, (one of the 3 founders of the Extreme Programming software development methodology circa) believes the goal with TDD is to write clean functional code. Another point of view is that the goal here isn’t about validation at all, rather it’s all about the specification.
The thought process here makes sense as developers are forced to think through the design and the requirements before writing a single line of functional code (which implies that TDD is important for both Agile design and Agile requirements).
Some other approaches to ensuring clean quality code in an Agile environment are as follows:
- Peer review
- Behavior-driven development (BDD)
- Pair Programming
The best approach here will be relative to team dynamics and the project. But for the most part, following best practices while taking on responsibility will go a long way to ensure that you are always working with clean quality code in an Agile environment.