Code Challenge 30 – The Art of Refactoring: Improve Your Code

By on 1 August 2017

A smooth sea never made a skilled sailor. – Franklin D. Roosevelt

Hi Pythonistas, a new week, a new ‘bite’ of Python coding. Wow challenge 30 already! This week we let you hone your refactoring skills. Learn, code, PR submit (don’t be shy) and above all have fun!

The challenge

The challenge is pretty simple:

  • Go through you code and identify something you think can be improved.

  • Write some tests to verify it does the right thing. This could be with Pytest, unittest or just adding a simple assert, just have a safeguard in place before starting to touch the code. Version control is your other friend here.

  • Iterate over various small improvements, running the tests after each step to verify nothing breaks.

  • When done submit a PR for our weekly review – this week we will be extra picky on PEP8 compliance! 😉

Update: somebody asked for scripts to refactor. Excellent point. As refactoring is such an important skill we will do a part II sometime soon where we will give you a couple of PyBites scripts to refactor!

Need help?

Here are some resources you could use:

PyBites

Worth checking out!

Books

Tools

Getting ready

See our INSTALL doc how to fork our challenges repo to get cracking.

This doc also provides you with instructions how you can submit your code to our community branch via a Pull Request (PR). We will feature your PRs in our end-of-the-week challenge review (previous editions).

Feedback

If you have ideas for a future challenge or find any issues, open a GH Issue or reach out directly.

Last but not least: there is no best solution, only learning more and better Python. Good luck!


Keep Calm and Code in Python!

— Bob and Julian

Want a career as a Python Developer but not sure where to start?