Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Is your helper library opinionated enough? (PyTexas 2014)

Paul Murphy
October 04, 2014

Is your helper library opinionated enough? (PyTexas 2014)

It's a constant debate.

How do you build a helper library?

At one end of the spectrum we have Runscope CEO John Sheehan who thinks that helper libraries are evil and shouldn't exist at all. At the other we find helper libraries that don't look or smell anything like the API. And somewhere in the middle we have helper libraries that are so close to the API itself that they are nothing more than a thin veneer.

Which is better? Who’s right? The real question to me is how idiomatic should a helper library be? Should a Django library make a Django developer feel comfortable, or should she have to read the API docs to understand how it works? Should a Python library look RESTful, or should it look like a hierarchy of classes?

At our company, we maintain two libraries. They both have advantages and disadvantages, they appeal to different developers, and sometimes even the same developer at different times.

Paul Murphy

October 04, 2014
Tweet

More Decks by Paul Murphy

Other Decks in Technology

Transcript

  1. Set the User-Agent def _get_headers(): user_agent = __api_lib_name__ + '/'

    + __version__ + '/' + PYTHON_VERSION return {'Authorization': 'Bearer ' + KEY, 'User-Agent': user_agent, 'Content-Type': ’…'}
  2. John Sheehan is a nudist Me Always cold. I like

    to help. Really. (He’s a control freak.)
  3. Hiding Scale { "total": 8, "limit": 2, "_class": "Collection", "_links":

    { "self": { "href": "/v1/bundles?limit=2" }, "items": [ { "href": "/v1/bundles/3fbca3fe3678495fb08fe939dbe4f1cd" }, { "href": "/v1/bundles/2a112c5b3e944802b932b0ddbf068c37" } ], "first": { "href": "/v1/bundles?limit=2&iterator=L1aa00000000000000000000000000000000h0" }, "last": { "href": "/v1/bundles?limit=2&iterator=L1ab00000000000000000000000000000000h0" }, "next": { "href": "/v1/bundles? limit=2&iterator=L1aa2a112c5b3e944802b932b0ddbf068c37h1396986421855" } } }
  4. Hiding Complexity class Bundle: def is_indexed(): # check media status

    … # check keyword status … # check topic status …
  5. { "id": "3fbca3fe3678495fb08fe939dbe4f1cd", "type": "audio", "name": "The Future of Women

    in Flying", "created": "2014-04-08T18:37:35.420Z", "_class": "Bundle", "_links": { ... }, "_embedded": { "clarify:tracks": { "bundle_id": "3fbca3fe3678495fb08fe939dbe4f1cd", "status": "ready", "created": "2014-04-08T18:37:35.425Z", "updated": "2014-04-08T19:05:13.719Z", "tracks": [ { "track": 0, "media_url": "http://archive.org/download/ Greatest_Speeches_of_the_20th_Century/TheFutureofWomeninFlying_64kb.mp3", ... "status": "ready", } ], ... }, "clarify:metadata": { ... } } }
  6. John Sheehan is a nudist Polar explorer pros •  No

    friction •  PnP with native modules •  Can absorb API changes •  Reference implementation •  Fewer customer bugs!
  7. John Sheehan is a nudist Polar explorer cons •  Bugs

    •  Hides information •  Wrong tradeoffs •  Often out of sync •  So much extra work!
  8. Ivo Rothschild Likes to wear clothes. Not too many, and

    not too few. Just the right amount.
  9. Result { "id": "ee1", "_class": "Ref", "_links": { "self": {

    "href": "/v1/bundles/XX" }, "curies": [ { "href": "/docs/rels/{rel}", "name": "PyTexas", "templated": true } ], "clarify:metadata": { "href": "/v1/bundles/XX/metadata" }, "clarify:tracks": { "href": "/v1/bundles/XX/tracks" } } } { u'id': u'ee1' u'_class': u'Ref', u'_links': { u'self': { u'href': u'/v1/bundles/XX' }, u'curies': [ { u'href': u'/docs/rels/{rel}', u'name': u'PyTexas', u'templated': True } ], u'clarify:metadata': { u'href': u'/v1/bundles/XX/metadata' }, u'clarify:tracks': { u'href': u'/v1/bundles/XX/tracks' } }, }