Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

When to Refactor Your Code into Generators and How

PyCon US via YouTube

Overview

Save Big on Coursera Plus. 7,000+ courses at $160 off. Limited Time Only!
Explore techniques for refactoring code into generators in this 27-minute PyCon US talk by Jan-Hein Bührman. Learn how to identify common loop patterns and transform them into more maintainable and Pythonic code using generator functions. Discover how to combine custom generators with standard library tools and third-party packages to create efficient code pipelines. Follow along with a practical example using the Fibonacci sequence to understand the before-and-after effects of generator-based refactoring. Gain insights into recognizing opportunities for this refactoring pattern and improving code maintainability. Access accompanying slides for visual reference and additional details on the concepts presented.

Syllabus

Intro
GOALS
TOPICS
VARIATIONS ON FIBONACCI NUMBER SELECTIONS
FIBONACCI NUMBER (DEFINITION)
FIBS LESS THAN N (PYTHON)
SMALLEST FIB GREATER/EQUALN(PYTHON)
THE PATTERN
TIME TO START REFACTORING YOUR CODE
CODE REFACTORING
EXTRACTING COMMON PARTS NOT DOABLE!
EXPERIMENT: COMBINE THE FIRST TWO FUNCTIONS
REFACTORING THE RIGHT WAY: SINGLE RESPONSIBILITY
CONTEXT SWITCH: GENERATOR FUNCTIONS
THE FIBONACCI NUMBER GENERATOR
EXAMPLE USAGE OF THE FIBONACCI GENERATOR
THE SMALLEST FIB GREATER/EQUAL N (PYTHON, REFACTORED)
RECAP

Taught by

PyCon US

Reviews

Start your review of When to Refactor Your Code into Generators and How

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.