Python Refactoring: From Functions to Classes for Efficient Coding

Опубликовано: 29 Сентябрь 2024
на канале: Pybites
961
61

Learn how Pybites can help you succeed in your Python journey: https://pybitesdevelopermindset.com/r... 🐍 💪
Join our Python Developer Community for free: https://pybites.circle.so/ 🌐👋
---

Welcome back to another Pybites refactoring video!

In today's video, we show you how to transform a set of functions into a class. This example will demonstrate when and how to use classes effectively.

We'll explore how a class maintains state, encapsulates data + behavior, reduces code repetition and can even improve the performance of your code.

By the end of this video, you'll have a clear understanding of refactoring techniques that can make your Python code cleaner and more maintainable.

Chapters:
00:00 Intro
00:23 Functions with repetition and using global scope
01:21 Writing a class and distinguishing config and user data
02:15 Make the functions methods
02:43 Using the instance variables in the methods
05:02 Fix the method calls
05:31 Making an instance to test this + IDE autocomplete
06:30 Calling the methods
07:01 Removing the setup repetition = less code + could be more performant
07:50 Wrap up

Resources:
- When to Write Classes in Python And Why it Matters: https://pybit.es/articles/when-classes
- When not to write classes:    • Stop Writing Classes  

Check out our dedicated refactoring playlist for similar videos:
   • Python Refactoring: From Functions to...  

---
Liked this video? Please give it a Like and subscribe to not miss any future videos. 📈 🙏

And to get our weekly developer / mindset emails, sign up for free here: https://pybit.es/friends/ 💡