3 ms·
> 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
by 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.