3 ms·
Author argues that named tuples are bad (it’s literally the article title) so I think you miss the point?
by notpushkin 2y ago
Author argues that named tuples are bad (it’s literally the article title) so I think you miss the point?
- PittleyDunkin 2y agoThe author also argues for readability over semantics, so I'm not sure they got the point to begin with.
- heavyset_go 2y agoThe author claims that the reason people reach for namedtuples is brevity, but I'd argue to the contrary and include the modern syntax for defining a namedtuple. The syntax is nearly identical to TypedDict and dataclass. There are other reasons to reach for namedtuples, for example when order or iterability matter. I don't see a general rule of not using namedtuples in APIs to be that useful. Use the right tool when the need calls for it.
- mont_tag 2y agoRight. It takes equal effort to define a named tuple, typed dict or dataclass. Mostly people just reach for the tool that does what they want, named tuples for tuply stuff, typed dicts for mapping applications, and dataclasses when you actually want a class.