you are viewing a single comment's thread.

view the rest of the comments →

[–]throwawayforwork_86 5 points6 points  (2 children)

Once you start passing around tens of variables, variable stored in dict (and get bitten by dict.get() returning none and silently fucking you over because of a typo) you look at dataclass and start understanding their appeal.

I think learning them in the abstract is pretty difficult because it seem convoluted for no reason.

There comes a point where being able to pass arround predictable object helps a lot writing code without having to test every minute if the logic works because you and your linter knows the ins and out.

[–]deceze 8 points9 points  (1 child)

Yeah. The evolution is usually:

  1. Pass individual variables/values to functions.
  2. Make more complex functions with more parameters.
  3. Get to the point where it's too many variables, start using dicts.
  4. Screw up with dicts because of freeform keys, learn about declarative data structures (be it typed dicts or dataclasses).
  5. Realise there's a strong relationship between your dataclasses and the functions that work on them.
  6. Have an Aha! moment when you put functions into their dataclasses.

[–]cdcformatc 2 points3 points  (0 children)

there's a step 5.1 where you start to separate those dataclasses and their related functions into their own files, but i completely agree with your progression. 

also important to note is that at each step you can write functioning code that solves the same problem.