Technical debt and Python
learn what is technical debt, various types of technical debts & how to identify and tackle in python
What is Technical debt?
Technical debt is an implied cost of additional rework caused by choosing an easier inefficient solution at the moment over a better approach that would take longer time to implement.
Technical debt increases over time for various reasons like team grows in size, system scaling and more product complexity.
Types of Technical debts
1. Intentional Technical debt
Intentional technical debts are the one you make deliberately. You know the best solution but still make a tradeoff and prefer a solution that can be implemented quickly. These kind of choices are made deliberately for several reasons,
- To deliver faster
- Too early to understand the problem correctly
To deliver faster
In most early stage teams, delivering faster and getting feedback from the customer is more important than having a best software architecture.
Too early to understand the problem correctly
Sometimes, as you build the product you wouldn't have the complete product domain expertise to create the correct abstractions. Creating abstractions too early can lead to inefficient leaky abstractions.
2. Unintentional Technical debt
Unintentional technical debts, also called as Accidental/Outdated Design debts which are made by accident. Major reasons for this category of debts are,
- Copy pasting code/designs from previous old projects/tutorials
- Lack of experience
Copy pasting code/designs from previous old projects/tutorials
The solution that worked on one project might not be efficient or work for a brand new project that is created today. For example, The latest python might have a best optimal solution or modules.
Another example we can mention is a solution that worked for 10000 users in an old project may not works for a scale of 1000000 users or a different market.
Lack of experience
Sometimes young engineers build solutions on their own instead of choosing a design pattern that solves the same problem better. Choosing correct design patterns means anyone can read the code and understand it because design patterns are transparent and there are plenty of learning materials available.
3. Bit rot Technical debt
Bit rot technical debts are mostly on legacy code. It usually happens when developers make small, incremental changes to the code that they don’t completely understand. These small changes eventually contribute to difficult situation where complete refactor is the only choice you have. Few reasons for this type of debt,
- Code complexity - code is difficult to read and make changes
- Lack of unit tests
- Lack of documentation
- Poor knowledge transfer
How to check if you have Technical debt?
Below are some indications that you have,
- Frequent bugs and patches to production
- Performance issues
- Tightly Coupled modules
- Can your code be changed to add new features or bug fixes in reasonable amount of time?
- Can tests be written for your code?
How to tackle Technical debt in python
Below are some design choices and tools that you use can reduce technical debts in python,
- Design patterns - choose correct design patterns
- Composition over Inheritance - composition makes code easy to modification
- Tests using pytest or unit test
- Code Coverage reports - coverage.py / pytest-cov
- Builtin documentation using python docstrings
- Loosely coupled microservices
- Static type checking in python to identify bugs early
- Code formatters - black
- Code linters - flake8
- Keep known technical debts documented in project backlog
If you find this article useful or any suggestion, please do comment below and share it others. Also connect with me on twitter to get my future articles
Great writeup and excellent points to keep in mind. Super helpful for those starting out too so that they know what to keep an eye out for!
Does this work in environments like .NET Core,too_