~/talk

When to refactor your code into generators and how

Talkat PyCon US 2022 · 2022-04-27..05-03· [python]
links:none on file
slides:none on file

Claim: factor the data-producing core out of similar loops into a single generator and compose behavior with iterator tools; concrete result is a reusable fibgen that yields an endless Fibonacci stream. Tools actually used: itertools.islice, itertools.takewhile, itertools.dropwhile and functions from the more-itertools package (one, chunks). The refactor replaces four messy variants with a generator + combinators, code is implemented and verified with pytest-bdd and works.

AI-written summary · about

  1. 0:00Intro
  2. 0:41GOALS
  3. 2:43TOPICS
  4. 3:23VARIATIONS ON FIBONACCI NUMBER SELECTIONS
  5. 4:00FIBONACCI NUMBER (DEFINITION)
  6. 4:58FIBS LESS THAN N (PYTHON)
  7. 8:28SMALLEST FIB GREATER/EQUALN(PYTHON)
  8. 9:23THE PATTERN
  9. 10:42TIME TO START REFACTORING YOUR CODE
  10. 11:05CODE REFACTORING
  11. 11:36EXTRACTING COMMON PARTS NOT DOABLE!
  12. 12:38EXPERIMENT: COMBINE THE FIRST TWO FUNCTIONS
  13. 13:29REFACTORING THE RIGHT WAY: SINGLE RESPONSIBILITY
  14. 14:52CONTEXT SWITCH: GENERATOR FUNCTIONS
  15. 16:55THE FIBONACCI NUMBER GENERATOR
  16. 18:30EXAMPLE USAGE OF THE FIBONACCI GENERATOR
  17. 23:35THE SMALLEST FIB GREATER/EQUAL N (PYTHON, REFACTORED)
  18. 25:31RECAP
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.