Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Why not…dicts #89

Closed
hynek opened this issue Sep 10, 2016 · 0 comments
Closed

Add Why not…dicts #89

hynek opened this issue Sep 10, 2016 · 0 comments
Milestone

Comments

@hynek
Copy link
Member

hynek commented Sep 10, 2016

Should contain stuff like https://twitter.com/cournape/status/769120659783950336:

sigh. attr really helps following a golden rule: if your dict has a fixed and known set of keys, it is an object, not a hash

https://news.ycombinator.com/item?id=12363487

Dictionaries are not for fixed fields.

if you have a dict, it maps something to something else. You should be able to add and remove values.

Objects, on the other hand, are supposed to have specific fields of specific types, because their methods have strong expectations of what those fields and types are.

attrs lets you be specific about those expectations; a dictionary does not. It gives you a named entity (the class) in your code, which lets you explain in other places whether you take a parameter of that class or return a value of that class.

@hynek hynek added this to the 16.2.0 milestone Sep 10, 2016
@hynek hynek closed this as completed in aad822a Sep 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant