SOLID Python part 1: Introduction

User profile image Johan Vergeer Jan 14, 2020 5 min read

SOLID is an acronym for the first five principles of Object-Oriented Design created by Robert C. Martin. These principles help us to develop software that can be maintained and extended throughout its lifetime. The SOLID principles do this by avoiding code smells, refactoring code and applying Agile Software Development.

This article series provides insight into the SOLID principles and how they can be applied to Python. In this first article we'll have a look at the reason we should apply the SOLID principles, some code smells, what technical debt is and how you can avoid it.

Design Smells

Before we get started with the SOLID principles I would like to start with design smells that will lead problems when we want to maintain, reuse or extend our software.

Rigidity - The system is hard to change because every change forces many other changes to other parts of the system.
Fragility - Changes cause the system to break in places that have no conceptual relationship to the part that was changed.
Immobility - It is hard to disentangle the system into components that can be reused in other systems.
Viscosity - Doing things right is harder than doing things wrong.
Needless Complexity - The design contains infrastructure that adds no direct benefit.
Opacity - It is hard to read and understand. It does not express its intent well.
Needless Repetition - The design contains repeating structures that could be unified under a single abstraction.
Robert C. Martin Agile Software Development, Principles, Patterns, and Practices

Technical Debt

Allowing technical debt into your code might be a conscious decision, which is usually because of a deadline. Whey we let technical debt grow consciously, we should also plan time after the release to clean up the code.

Technical debt can also grow because of a lack of knowledge, bad design and a lack of standards and common practices.

Facts about technical debt

Here are some facts about technical debt to keep in mind:

It will accumulate over time.
It will increase the cost of change.
It will decrease the responsiveness to your customer.
It will kill your project if you don't keep it under control.

How to keep control of technical debt?

To keep control of technical debt there are three simple steps we can use:

Step 1: Write code. (Don't forget about the tests)
Step 2: Clean up code. (a.k.a. refactor code)
Step 3: Repeat

Back to the SOLID principles

So why would we use the SOLID principles when we're working on our code? Well, it helps us to write code that is ...

... easier to understand
... easier and faster to apply changes to
... better maintainable
... more cost effective