3 ms·
Namedtuple is used a lot in the standard library to return struct-like results which used to be returned as an actual tuple, so making them non-indexable would
by gvx 9y ago
Namedtuple is used a lot in the standard library to return struct-like results which used to be returned as an actual tuple, so making them non-indexable would break a lot of code, some of which was written before namedtuple even existed.
- eesmith 9y agoI did that analysis a day ago when this topic came up previously, at https://news.ycombinator.com/item?id=15136961 https://news.ycombinator.com/item?id=15136961 . There are 13 locations in the standard library where a namedtuple was used to replace a tuple, where making them non-indexable would break code. There are 8 locations where it's used as a shorter way to write a simple class. My point in that thread was that namedtuple should never be used this way.
- gvx 9y agoI think namedtuple is a terrible hack that never should have been (at least not this way), but changing it is going to be a PITA.
- deleted 9y ago[deleted]
- goldenkey 9y agoWhats beautiful about JS is that an Array can also be used as an object. ie...namedtuple in JS var nt = [a, b, c] [nt.a, nt.b, nt.c] = nt nt.freeze() // now immutable