Extract Method Refactoring Example in Python

preview_player
Показать описание
In this video, we delve into a common scenario where a function takes on too many responsibilities, a situation you might have encountered with inline comments outlining sub-functionalities. It’s time to refactor!

Armed with a regression test suite, we employ the "Extract Method" refactoring technique to decompose the original function into three smaller, more manageable functions. This approach enhances code readability, maintainability, and reusability.

We’ve kept it simple to illustrate the concept, but we challenge you to apply this technique to your own code! Share your experiences and examples in the comments below – we’d love to hear how it worked out for you.

Chapters:
00:00 Intro and explanation of the technique
00:22 The code to refactor
00:50 Inline comment smell
00:59 Have tests!
01:59 Breaking out the first block
02:58 Could also pass in an optional argument
03:29 Validating the refactoring running tests
03:48 Breaking out second block of logic
04:18 Run the tests
04:25 Break out the last block of code
05:00 More readability
05:28 Add some more type hints and fix an error
06:00 Conclusion
06:30 Wrap up

Learn More About PyBites:

Don’t forget to like, subscribe, and share this video with fellow coders! 🙏 Keep calm and refactor in Python! 💪
Рекомендации по теме
Комментарии
Автор

Stay tuned for next refactoring one: flat is better than nested. What else would you like to see refactoring wise?

pybob
join shbcf.ru