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 clean code
Exploring the Role of Static Methods in Python: A Functional Perspective
By Bob Belderbos on 24 January 2024
Introduction Python’s versatility in supporting different programming paradigms, including procedural, object-oriented, and functional programming, opens up a rich landscape for software design and development. Among these paradigms, the use of static methods in Python, particularly in an object-oriented context, has been a topic of debate. This article delves into the role and implications of static… Continue reading Exploring the Role of Static Methods in Python: A Functional Perspective
Why Start Your Programming Journey With Python?
By Sherry Andrews Bhutia on 19 September 2023
Diving into Programming with Python I’ve spent years entertaining the thought of becoming a software developer, only to get overwhelmed by the vast array (pun intended) of programming languages to choose from. Which one should I choose, where do I begin? Java? JavaScript? C? C++? C#? Ruby? Django? Flask? Woah… wait a minute? Understanding Frameworks… Continue reading Why Start Your Programming Journey With Python?
Write more maintainable Python code, avoid these 15 code smells
By PyBites Team on 15 September 2023
This week we talk about code smells. 💡 Listen here: Also available on our YouTube channel: Code smells are characteristics in the code that might indicate deeper issues or potential problems. While they’re not necessarily bugs, they can be a sign of poor code quality or maintainability issues. 😱 We distilled 15 common smells ranging… Continue reading Write more maintainable Python code, avoid these 15 code smells
How the Flocking Rules Can Help You Refactor Your Code
By PyBites Team on 10 August 2023
In this new podcast episode we are excited to have Chris May back to delve deeper into the intricacies of refactoring. Watch here: Listen here: We talk about the significance of the Flocking Rules, a set of guidelines derived from “99 Bottles of OOP” by Sandi Metz and Katrina Owen. These rules provide developers with… Continue reading How the Flocking Rules Can Help You Refactor Your Code
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)
The importance of refactoring regularly [podcast]
By PyBites Team on 15 June 2023
In this episode we talk with Chris May, Python developer and coach, about his background and passion for refactoring. Watch here: Or listen here: This turned into a beautiful love letter 💌 to refactoring and we think you should take notice, because adopting the mindset he teaches will improve your code. A lot! Enjoy and… Continue reading The importance of refactoring regularly [podcast]
Tips for clean code in Python
By Bob Belderbos on 8 November 2022
In this article I will give you 10 tips for cleaner code. Hope this helps improve your Python code. 1. Smaller units. Break long functions (methods) into multiple smaller ones that do one thing (SRP or “Single-responsibility principle”). This will make your code more modular and easier to test. For example, a function that parses… Continue reading Tips for clean code in Python
A Case Study in Refactoring Python: Clean Code Is Often Faster
By Russell Helmstedter on 20 July 2022
I have learned a lot over the past 2.5 years of my Python journey. What started out as a hobby during COVID-19 lock downs in 2020, has now become a major component of my professional workload. This article is designed to highlight the importance of the iterative process: write some code -> learn new stuff… Continue reading A Case Study in Refactoring Python: Clean Code Is Often Faster