This is a follow-up post to Stop naming your Python modules “utils”. This time, let’s see different options on organizing utility code. What is utility code? It is code that is created as a side effect when working on features but does not belong to where they are implemented. It still is necessary or convenient […]
Category: good practices

Modular monolith in Python
Microservices are not the only way I remember when the microservices boom started. Truth to be told, it still echoes strongly to this day. You could see conferences agendas packed with talks about microservices, articles galore, finally books and frameworks. At some point, I was afraid to open my fridge. Everyone and their dog wanted […]

@staticmethod considered a code smell
Python offers quite a few built-in decorators that can be used to give methods of classes certain superpowers. @property turning method into a read-only field-like attribute is a classic example. Or @classmethod – a method that receives a class as a first argument, not an instance. Fun fact, this kind of method is usually called […]

Encapsulation is your friend, also in Python
What is encapsulation? Encapsulation is an act of deliberate limiting access to certain software components. The most common usage is to hide certain attributes of objects from other objects that use it. The most vivid example is the usage of so-called access modifiers, private and protected in languages that support it, for example, PHP: Running […]

Beware of chicken testing! (or mocks overuse)
Need for mocking Dealing with problematic dependencies is an indispensable part of software testing. Often, we cannot or do not want to rely on 3rd party service/network communication/hard drive etc., especially in unit-tests. The reasons vary; external dependencies are usually slow, fallible and difficult to put into the expected state before the actual test. Consider […]

Stop naming your python modules “utils”
Imagine the following situation: there is a software developer that is either adding new code or refactoring existing one by extracting a class/function. They have to place code somewhere, but it does not seem to fit anywhere. So what does a developer do? They create a new module – utils.py. Why utils is a terrible […]