Skip to content Skip to footer

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

[ad_1]

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

Photo by Lucas Davies on Unsplash

Introduction

Code refactor challenges are well-known by software engineers, 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 quality and object-oriented. Mastering the SOLID principles as a data scientist can substantially elevate the quality and manageability of data science projects. This is particularly crucial in teams in which most data scientists are statisticians and mathematicians by origin, who may have less familiarity with programming 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 context 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 improve 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 python 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
source .venv/bin/activate # on mac or linux
# .venv\Scripts\activate # on windows
pip install -r requirements.txt
pytest

[ad_2]

Source link