Hacker News new | past | comments | ask | show | jobs | submit login

My take is that dicts are fine as long as your code is well tested. Yeah, dataclasses and frozen classes have much better typing support, but if you code is mostly reading and writing JSON like many modern cloud apps, it can be easier to use plain dicts combined with decent tests to make sure you don't break downstream services.



I’m currently in the middle of refactoring a well-tested but dict-ly typed Python codebase into dataclasses.

Once your app involves a certain amount of business logic, those dicts just beg for you to shove in just that one more temporary field that you’ll be needing later in the calculation.

Of course you can abuse classes just the same. But I feel it happens less often. There’s more social control. The type has a name now. And you have to visit it at home whenever you’re trying to add a field to it. My impression is that some people are underestimating the psychological power of those nudging factors.


Refactoring those services sucks though if the data model changes. :(




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

Search: