Easier Classes: Python Classes Without All the Cruft
summary
Shows how to get rid of boilerplate by using dataclasses (Py3.7), attrs, and namedtuple instead of hand‑rolled classes, demonstrating concrete code for string repr, equality, hashing, iteration (dunder __iter__), immutability (frozen=True), and ordering (order=True or functools.total_ordering). Illustrates pitfalls: namedtuple inherits tuple behaviors you may not want and attrs is third‑party, dataclasses are built in but backportable, and some tiny class uses (matrix, space_age) are simpler as plain functions rather than objects.
AI-written summary · about
chapters (7)
- 0:00Intro
- 2:11Case 1: Month class
- 4:53Case 2: Point class
- 8:15namedtuple
- 15:43dataclasses
- 20:10Friendly Class Recipes
- 25:26Advanced Recipes
related talks
22mEasier Classes: Python Classes Without All The Cruft
26mEverything you need to know but were afraid to ask about Data Classes
45mDataclasses: The code generator to end all code generators
46mOn Being Pythonic
01h 10mIt's Pythons All The Way Down: Python Types & Metaclasses Made Simple
33mElegant Solutions For Everyday Python Problems
47mA Deep-Dive Into Python Classes
19mObjects and classes in Python (and JavaScript)
