Solving a Tennis Refactoring Challenge in Python using SOLID | by Tomer Gabay | Feb, 2024

A step-by-step illustration of how to use SOLID to solve a refactoring challenge

Tomer Gabay
Towards Data Science
Photo by Lucas Davies on Unsplash

Introduction

Code refactor are well-known by software , but less so by data scientists, though data scientists can also highly benefit from practising such challenges. By practising these, especially when applying the SOLID principles, you learn how to write much better code; code that’s modular, of high and object-oriented. Mastering the SOLID principles as a data scientist can substantially elevate the quality and manageability of data projects. This is particularly crucial in teams in which most data scientists are statisticians and mathematicians by origin, who may have less familiarity with fundamentals than software engineers.

There are many refactoring challenges available online. Perhaps the most famous one is the Gilded Rose Kata. Another fun refactoring kata is the Tennis Refactoring Kata, which we’ll tackle in this article.

Often these challenges are called katas, In the of a “refactoring kata,” the word “kata” is borrowed from martial arts, where it refers to a structured practice routine. In martial arts, a kata is a sequence of movements and techniques that are practiced repeatedly to skill and fluency.

https://github.com/emilybache/Tennis-Refactoring-Kata (MIT license)

Go to https://github.com/emilybache/Tennis-Refactoring-Kata and select “Use As Template” in the green top right button.

Clone the template and enter the repository in your terminal. Then, cd into the directory, create a virtual environment and install the dependencies. To test if everything works run pytest. You can copy-paste the commands below into your terminal.

cd python
python -m venv .venv
.venv/bin/activate # on mac or linux
# .venv\Scripts\activate # on
pip install -r requirements.txt
pytest

Source link