Skip to content

Add a philosophy section #73

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

Merged
merged 1 commit into from
Aug 30, 2016
Merged

Add a philosophy section #73

merged 1 commit into from
Aug 30, 2016

Conversation

hynek
Copy link
Member

@hynek hynek commented Aug 28, 2016

Also expand the example class a little bit to stress that we're not just
about data containers.

This is kind of a response to questions and concerns that come up in issues – and places that shall not be named – frequently.

I’d some love feedback from people who understand attrs and what it stands for. Ideally also from people who have better words than I.

I really just want to link there and drop the mike in the future.

cc @hawkowl @glyph @cyli @econchick @Tinche @cournape @mithrandi

@hynek hynek added this to the 16.1 milestone Aug 28, 2016
@codecov-io
Copy link

codecov-io commented Aug 28, 2016

Current coverage is 100% (diff: 100%)

Merging #73 into master will not change coverage

@@           master   #73   diff @@
===================================
  Files           8     8          
  Lines         395   395          
  Methods         0     0          
  Messages        0     0          
  Branches       87    87          
===================================
  Hits          395   395          
  Misses          0     0          
  Partials        0     0          

Powered by Codecov. Last update ce0f82a...880a353

Also expand the example class a little bit to stress that we're not just
about data containers.
@hawkowl
Copy link
Member

hawkowl commented Aug 28, 2016

👍

@Tinche
Copy link
Member

Tinche commented Aug 28, 2016

If by 'places that shall not be named' you mean Hacker News like was mentioned on Twitter, I don't go there so I don't know exactly what their complaints are.

I use attrs a lot for what you call 'data-only' containers (Java folks would call these DTOs I guess, or data transfer objects), maybe with some properties or helper methods mixed in. You make a point of attrs not being only for this kinds of classes, but I find 1) attrs works best for these kinds of classes and 2) it's actually in your best interest to have many of these kinds of classes. So I like the fact attrs is opinionated (as much as it is) and I like its opinions :) I'm not sure how to turn this paragraph into an actionable item for the philosophy section :)

Another thing I love about attrs is that it's declarative. It's a damn shame we've had to wait this long to get proper declarative classes into Python (with an API I actually want and like to use). An anecdote: I work in mobile games. We use Python on the backend and, nowadays, C# for the games themselves. There is data that's shared between the client and the server, things like request and response formats, the player save game, and game data itself (every game has a database of domain-specific data, for example a cooking game might have a list of food, ingredients, appliances, restaurant furniture etc). Recently I've started using attrs for some of these classes on the backend, where before they used to be pure dictionaries. Now that we have this data in a declarative format in code, I'm seriously considering generating C# classes from them, so we'd have to define our data only once and save a bunch of manual labor. attrs makes this possible and easy.

Maybe another thing we could touch on is structured data vs unstructured data, and how attrs classes are superior to dictionaries. For example, when you turn your unstructured data into classes, there's validation at the point of conversion instead of point of use, which is exactly what you want. Type checking becomes possible (I don't know how well mypy handles attrs, but PyCharm handles them just fine with extra type hints, and I rely on this daily, for correctness and autocomplete).

I'm not sure this is material for the philosophy section, more for the "why" section. My philosophy would be 'use attrs for what it's great for, and reap the massive benefits it brings, even if you have to change your thinking a little'.

@hynek hynek merged commit 41d8cce into master Aug 30, 2016
@hynek
Copy link
Member Author

hynek commented Aug 30, 2016

I’d wish to expand the “why not dicts” section but I’m tired and out of words. if someone could write something coherent, that would be really greeeeat. ;)

@hynek hynek deleted the philosophy branch August 30, 2016 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants