3 ms·
Python has two great ways to write immutable "ValueObjects": - Dataclasses w/ the `frozen=true` kwarg - namedtuple They add some headroom to programs, but I f
by xavdid 4y ago
Python has two great ways to write immutable "ValueObjects":
- Dataclasses w/ the `frozen=true` kwarg
- namedtuple
They add some headroom to programs, but I find they help _immensely_ for readability and fewer bugs.
Bonus, each works out of the box for equality testing (two objects are "==" if they're of the same type and the values of each of their fields are equal)