4 ms·
You can even subclass namedtuples to get immutable value objects with helpful methods. I like classes over dictionaries because I can look at the class definit
by Scarblac 7y ago
You can even subclass namedtuples to get immutable value objects with helpful methods.
I like classes over dictionaries because I can look at the class definition to see what the variables my function gets are, and what functions (methods) exist to work with them.
I used to work with a code base that passed dictionaries around, and there were a lot of hacks where people had some data somewhere that they needed somewhere else, and the dict was available both places, so why not add it to that... Different pieces of code added different things and you were never quite sure which version of the data was passed this time for the "layers" parameter. Somehow it doesn't happen as much with classes.
It was like duck typing to the extreme. I call it smurf typing, if it smurfs like a smurf, smurfs like a smurf and smurfs like a smurf, nobody knows what's going on anymore.
Immutable value classes, those are good.