Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A little off topic, but the article mentions:

> There are three reasons to use dataclasses over attrs:

Another, not in this list, is that since it is in the standard library, co-workers/contributors are significantly more likely to have heard of dataclasses and already know its interface. Another reason, sort of along similar lines, is the fact that that dataclasses has fewer features than attrs - the author mentions this as a disadvantage, but actually it's a benefit if it has the features you need, because a simpler library is less cognative overhead to write and maintain code against.



In my experience way more Python devs know and are comfortable with attrs than dataclasses simply because its been around much longer.

Devs moving off of attrs generally go to pydantic in my experience.

Direct usage of dataclasses is literally zero across several python companies and many python codebases I have worked with.


One nice thing about making this decision is that the decision rubric for choosing between dataclasses and attrs is really straightforward. In addition to all the reasons the article lists for why you might need to use dataclasses, I'd personally also default to them unless I know I need one of the things that attrs does better: robust validation, or performance.

The nice thing here is that, since dataclasses are more-or-less just slimmed-down attrs, it's relatively easy to migrate from dataclasses to attrs at a later date.




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

Search: