O'Reilly logo

Building Maintainable Software, Java Edition by Gijs Wijnholds, Pascal van Eck, Rob van der Leek, Sylvan Rigal, Joost Visser

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Write Clean Code

Writing clean code is what you must do in order to call yourself a professional.

Robert C. Martin

Guideline:

  • Write clean code.

  • Do this by not leaving code smells behind after development work.

  • This improves maintainability because clean code is maintainable code.

Code smells are coding patterns that hint that a problem is present. Introducing or not removing such patterns is bad practice, as they decrease the maintainability of code. In this chapter we discuss guidelines for keeping the codebase clean from code smells to achieve a “hygienic environment.”

Leave No Trace

Boy Scouts have a rule that says, “leave the campground cleaner than you found it.” Applying the Boy Scout rule to software development means that once you are writing or modifying a piece of code, you have the opportunity to make small improvements as well. The result is that you leave the code cleaner and more maintainable than you found it. If you are adjusting a piece of code now, apparently there is a need for maintaining it. That increases the chance that you will revisit that same code later. When you revisit that code again, you will benefit from the refactoring you are doing now.

How to Apply the Guideline

Trying to be a clean coder is an ambitious goal, and there are many best practices that you can follow. From our consultancy experience we have distilled seven developer “Boy Scout rules” that will help you to prevent code smells that impact maintainability most: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required