Hacker News new | ask | show | jobs
by ledauphin 1641 days ago
there are newer (since 2020) syntactic constructs that might be more to your liking. take a look at the docs again.

Incidentally, I'd recommend against Named Tuples for non-trivial software. Because they can be indexed by integer and unpacked like tuples, additions of new fields are backwards-incompatible with existing code.

2 comments

yeah this has bitten me before. combine it with overwriting len for a namedtuple and you have a proper mess
I don't like newfangled syntactic constructs since they hide what is going on. :) The example in the article was a Point3D class and for that namedtuple is a good choice (points should be immutable). It's unlikely that you'd want to add fields without also making other backwards-incompatible changes.