3 ms·
I feel like "consider dataclasses as a useful default" is decent advice. You get the stuff you get from `NamedTuple`, but you can also easily add helper method
by rtpg 2y ago
I feel like "consider dataclasses as a useful default" is decent advice.
You get the stuff you get from `NamedTuple`, but you can also easily add helper methods to the class as needed. And there are other dataclass goodies (though some things I find to be a bit anti-feature-y).
- heavyset_go 2y ago> I feel like "consider dataclasses as a useful default" is decent advice. I agree. > You get the stuff you get from `NamedTuple`, but you can also easily add helper methods to the class as needed. And there are other dataclass goodies (though some things I find to be a bit anti-feature-y). I've seen examples where dataclasses were used when order matters, however, hence why I'm not comfortable with a general rule against namedtuples. Sometimes order and iterability matter, and dogmatically reaching for a different data type that doesn't preserve that information might be the wrong choice.
- david2ndaccount 2y agoYou can have methods with NamedTuple
- rtpg 2y agoOh, with the class declaration version? I never considered that, but feels obvious now.