Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


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.


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


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: