Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Way to manage program state in Python, without OOP?
8 points by wheelerof4te on Jan 24, 2022 | hide | past | favorite | 2 comments
What is the best way to manage state in Python, without resorting to classes?

Do you use dataclasses, or keep everything as close to functional as you can? I don't find Python's object oriented style pythonic, and would prefer more C-like program structure.

How can I efficiently and cleanly manage state in Python? Please share your solutions.



It depends on the complexity of the problem. Data classes can make the code easy to read, and if you use a good IDE then it will also be faster to write.

I suggest you focus on making the program work, before considering how to best manage state. Readability and performance can be improved through refactoring later.


I agree, good point.

I was just trying out something in a game, and minimizing mutable state has lead to some interesting ideas. Not to mention that it trivilized creation of custom data types.




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

Search: