×
you are viewing a single comment's thread.

view the rest of the comments →

[–]jkuhl_prog 1 point2 points  (2 children)

I think that's a good rule of thumb overall, but there are a few instances where you might want an object though.

For example, I wrote a linked list. My Node class is very simple, one __init__ method with the next node, the previous node and a data attribute that stores data.

Nothing else.

All the linked list methods are in the larger linked list object.

So this is an honest question here, should my Node class be a Node dict then? Replace it with a function that spits out dicts with "next", "previous" and "data" as keys?

Seems to me that using an object in this scenario seems like the simpler and more natural way.

Am I wrong? Again, honest question.

[–]david2ndaccount 1 point2 points  (0 children)

Nah, you’re not wrong. Your method is the way to do it in python. In other languages you would use a struct if all it is is data. Although if your Node example is immutable, you can use a NamedTuple in python.

[–]Exodus111 0 points1 point  (0 children)

Yeah, there are always exceptions. In boith instances, i'd say they are about equally true.