top | item 44675796

(no title)

rosmax_1337 | 7 months ago

I fail to see any argument why the namedtuple beats the usage of a class here. A class in a development view of the problem, is also a structure to build and expand upon, a tuple is a promise this won't be expanded upon. Clearly case dependent which is better.

discuss

order

SamuelAdams|7 months ago

It also makes the code easier to read, and that is what our org optimizes for, all else being equal. Code is read 10x more than it is modified, so if you can make it a little quicker to understand it’s generally recommended.

sgt|7 months ago

But then why not use dataclasses and get constructor, equality etc included?

JohnKemeny|7 months ago

namedtuple is not a replacement for a class, but for a tuple. It is a tuple with named accessors.

You can also argue that you don't need a Pair type since you can simple make a class for the two things you want to contain.