The repository pattern is a design pattern that helps you separate business logic from data access code. It does so by providing a unified interface for interacting with different data sources, bringing the following advantages to your system: A practical example Let’s use Python and sqlmodel (PyPI) to demonstrate this pattern (code here): Note: In this implementation,… Continue reading What is the Repository Pattern and How to Use it in Python?
Articles on maintainability
⚠️Why you should avoid import * in Python 🐍
By Bob Belderbos on 15 August 2023
Anyone who’s worked with Python knows that modules can be a Godsend, saving you time, effort, and many lines of code. They even have namespacing built-in 💪 😍 To expand on this a bit: However, not all ways of using modules are equally beneficial. In this article, we will discuss why using import * can… Continue reading ⚠️Why you should avoid import * in Python 🐍
The Arbitrary (Keyword) Arguments (args and kwargs) don’t come “for free” in Python
By Bob Belderbos on 9 August 2023
Python allows you to use *args and **kwargs in function definitions to accept an arbitrary number of positional and keyword arguments, respectively. Here is a simple example: Different types of function arguments In the above example, the arbitrary_args function is defined to accept any number of positional and keyword arguments using the *args and **kwargs… Continue reading The Arbitrary (Keyword) Arguments (args and kwargs) don’t come “for free” in Python
Why is Flat Better Than Nested? (Zen of Python)
By Bob Belderbos on 1 August 2023
The short answer: deeply nested code can be hard to read and understand (and this not only applies to Python, but for any code really). Each level of indentation adds a level of complexity and an additional condition that the reader (which is often you!) has to keep in their head while trying to understand… Continue reading Why is Flat Better Than Nested? (Zen of Python)