Writing clean code that is easy to test and maintain is much harder than it seems at first glance. Fortunately, Go, as a programming language, is quite opinionated and comes with its own set of best practices.
If you take a look at some of the available material for learning Go (for example, Effective Go [6]) or watch some talks by prominent members of the core Go team such as Rob Pike, it becomes evident that software engineers are gently nudged toward applying those principles when working on their own Go projects. From my perspective and experience, these best practices tend to have a measurable positive effect on the code quality metrics associated with a code base and at the same time aid in minimizing the accumulation of technical debt.
In this chapter, we will cover the following topics:
- Understanding the SOLID principles of object-oriented design through the eyes of a Go engineer
- Organizing source code at the package level
- Helpful tips and tools for writing lean and easy-to-maintain code in Go