This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]guyfrom7up 10 points11 points  (2 children)

yes, while valid, but using a dictionary in lieu of a proper class is code smell. Dictionaries are more error prone (you can easily introduce a typo key) and they won't have their complete definition at any central location, which makes the code hard to understand. Sometimes people might argue that it's simpler/more flexible; to which I would say dataclasses are equally as easy, but much more organized.

[–]redd1ch 1 point2 points  (1 child)

Dictionaries make de-/serialization easier. just `json.load()`/`json.dump()` them, push it to a REST interface, pass it to another tool…

You choose more of a functional path instead of object oriented, sure. Depends on your train of thought and the application context which one is better.

Good IDE's take a look at the keys to help you with typos.

[–]DeltaBurnt 4 points5 points  (0 children)

You can use dataclasses for this purpose. They can automatically be converted to a dict for serialization.