Refactoring for fun and profit
summary
Refactors a messy Python side project that computes and annotates minimum paths for a train game into small classes and clear entry points, using Black for formatting, linters and an IDE for automated renames and extracts, and MonkeyType plus mypy for adding and checking types. Profiling with a Scalene profiler finds a hotspot in coordinate creation, fixed by moving work off init and using cached_property; tests and integration checks keep behavior stable and make collaboration possible.
AI-written summary · about
chapters (29)
- 0:00Start
- 0:40Intro
- 3:30Formatting
- 4:19Pragmatism
- 5:03Linting
- 5:43Abstraction, Interface Segregation, & Dependency Inversion
- 8:42Is there a better way?
- 9:10Refactoring using IDEs
- 10:51Benefits of typing
- 11:58Adding types with MonkeyType
- 12:47Documentation through typing
- 14:47Documentation through structure
- 17:12Benefits of Python's amazing argument system
- 19:00Single Responsibility Principle
- 19:47DRY Principle
- 20:53Caveats of Utils
- 21:21Is there a better way?
- 21:42KISS Principle
- 23:09YAGNI Principle
- 23:40Benefits of testing
- 24:13Refactoring for testing after violating Dependency Inversion
- 25:24Profiling using Scalene
- 26:16Benefits of functools.cached_property
- 27:33Profit?
- 27:53Resources
- 28:08Outro
- 29:26Question: What would you do to ensure that you don't accidentally break things, when refactoring with no tests?
- 31:23Question: Is there a format for docstrings that are a good replacement for typing, since setting up typing is not always an option?
- 33:19Question: Do you prefer to omit types and instead use docstrings to provide context for complex nested types?
related talks
21mTeach Your Old Code New Tricks: Automating Code Quality in Large Projects
38mMigrating existing codebases to using type annotations
03h 38mPython Types for Fun and Profit
30mClearer Code at Scale: Static Types at Zulip and Dropbox
01h 33mFrom Raw Recruit Scripts to Perfect Python
42mInheriting a Sloppy Codebase: A Practical Guide to Wrangling Chaotic Code
34mScaling the Mountain: A Framework for Tackling Large-Scale Tech Debt
24mPython for Humans, Designing Python Code Like a User Interface
