9 ms·
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 ex
by rosmax_1337 1y 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.
- JohnKemeny 1y agonamedtuple 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.
- SamuelAdams 1y agoIt 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 1y agoBut then why not use dataclasses and get constructor, equality etc included?