Why It’s Critical to Write and Deliver Clean Code

clean code driven development

Back in 2007, a famous software expert Robert C. Martin (a.k.a. Uncle Bob) published the first edition of a book called “Clean Code: A Handbook of Agile Software Craftsmanship”. In it, he set forth a then-revolutionary paradigm that poorly written and unclean code can bring any development organisation to its knees.

While bad code can still function to some extent, it typically causes a lot of issues down the road, which costs money and time to fix and eliminate. Poorly written code is so hard to interpret and understand by others that it can be less time-consuming and expensive to rewrite it from scratch in most cases.

Bad code means countless hours and significant resources were wasted just because some developer didn’t bother to provide appropriate commentary, name objects properly or format code for better readability.

Evolve Client Case

Offerd is a UK-based startup that’s building an ultimate digital workplace for recruiters. Their founder wasted more than £100,000 and risked losing his project because of a rogue outsourcing agency that delivered unreadable and non-reusable code. Having done the due diligence of the deliverables provided by the previous tech partner, we chose to rewrite the entire code instead of trying to fix the old one and make it readable. Having fixed the code, Offerd could onboard the first clients and start making money while still in an MVP stage.

The key advantage of clean code is a more stable and maintainable program. According to different studies, as much as 80% of all software maintenance efforts are spent on understanding code written by a different development team.

Clean Code Features

Two years after the release of Robert C. Martin’s book, in 2009, Stefan Lieser and Ralph Westphal created the Clean Code Developer Initiative which divided all coding principles and practices into five levels marked in different colors: red, orange, yellow, green and blue (see image).

Based on that, they could define the main features of clean code:

  • Simplicity 
  • Focused
  • No redundancy
  • Pleasant to read
  • Easily extended by any other developer
  • Minimal dependencies with other elements
  • Unit and acceptance test cases are in place

In addition, the Initiative could identify key barriers preventing teams from writing and delivering clean code:

  • Unclear requirements that change often
  • Lack of clean code training
  • Lack of programming correction
  • Lack of code refactoring
  • Tight project deadlines and lack of proper code review processes 

How to Implement Clean Code Practices Within Your Team

As a bespoke software development company, we at Evolve encourage our client-tailored teams to implement the above principles and practices to ensure the delivery of the best code ever.

Clean Code Challenges

One of the ways to motivate our teams to commit clean code is to conduct the so-called Clean Code Challenges between teams and incentivize the winners. If you have a big in-house team, ask your PM /tech lead to divide it into 2-3 groups of 3-5 members each. If you have several teams, provide each with the same source code and ask them to review and evaluate its quality against the following parameters:

  • Static/dynamic code review in design and identification of critical and major violations;
  • Non-functional requirements:
    • Readability
    • Testability 
    • Debuggability 
    • Configurability
    • Scalability
    • Reusability 
  • Assessment against OWASP principles

Upon the review, each team has to compile and submit review assessment reports containing top critical and major code violations backed up with evidence and suggestions for improvement, top OWASP vulnerability issues and how to fix them, 3-5 recommendations on how to deliver clean code.

The winning team should get a tangible or intangible incentive to feel motivated to keep practicing clean code.

Set Clean Code Development Rules

In our company, all PMs and tech leads require that their team members do the following things on a regular basis to instil clean code culture inside teams:

  1. Always use short and precise names for all classes, functions and variables;
  2. All functions and classes should be small and adhere to the single responsibility principle (SRP): functions should be no more than four lines, classes – no more than 100 lines, each should do just one thing;
  3. Unit-test the code as often as possible;
  4. Functions should have no side effects (e.g., modifying an input argument). This should be specified explicitly in the function contracts where possible.

Initiate and Encourage Regular Code Reviews

In fact, there’re many ways for development organizations to do code review, and each company is free to choose the ones that are better suited for their particular case. Code review is a must-have practice at Evolve and other mature tech consultancies. However, a lot of software houses are still ignoring or lacking this practice due to no internal bandwidth or tight project schedule, etc.

how to define software code quality

Although a single person can do code review, it’s still recommended to involve at least two people in the process. Each highlighted issue should be addressed and discussed throughout before a new piece of code can be committed. To speed up and facilitate the process of code review, each new piece of code should be tested with unit and integration tests or via pair programming on the screen.

Benefits of Clean Code Driven Development

Besides eliminating any hidden agenda and overheads at post-release stages, clean code-driven development can double or even triple your team’s productivity in the long run as well as improve the overall morale of your engineering teams. Studies show that up to 80% of Agile teams with a deeply embedded clean code culture are more productive and feel happier than their counterparts that don’t follow clean code dev principles.

In conclusion, clean code is no longer just a nice-to-have feature; it’s a must-have practice that takes your software engineering efforts to the next quality level and ensures long-term benefits without overblown budgets.

Are you going to embark on a software development journey but aren't sure where to start? Get in touch with Evolve and let's discuss how we can help!

Create your account