Refactoring Exercise (2/3) - Making use of Pythons Built-in Powers

The cleaning story continued - Built-Ins are coming! In the first post, we looked at cleaning our code on the block level. We identified two import blocks we moved to a separate function, several similar blocks of mappings we replaced with a for loop. In this post, we will look at the next level of granularity. We will check the code for further repetitions and see where code style can be improved to become less imperative.…

Refactoring Exercise (3/3) - Abstraction an Types are fun!

From chaos to code - Embeding Type Checking, Exensibility, and Security In our previous posts we went through a horrible piece of code and cleaned it (DRY principle) and create a stronger OOP logic. In itself the code is good and clean. Still it has substantial flaws, if we look at it from the outside. What happens, if we would like to employ a different search strategy but a union search on all options?…

Refactoring Exercise (1/3) - Step-by-step improving python code

Stage 1 - Understand the objectives and making it DRY Looking for a good exercise on python code refactoring that is suitable for beginners, I came across this repository: https://github.com/lamchau/refactoring-exercise. Thank you to Lam Chau for making this publicly available! So, let’s get started with reworking this very “elaborate” piece of software craftsmanship ;-) After cleaning the direct and obvious formal flaws from the code (Indenting according to PEP8 with 4 Spaces and an unused variable: https://www.…