Episode 008: Twitter, Plated
Christoph tries to figure out why Twitter stopped talking about Clojure.
- “Are you twitterpated?”
- Building on where we left off last episode.
- Runs and just stops working.
- “I was pretty sure it stopped working because people on Twitter just stopped talking about Clojure. After about a day of that, I realized people were talking about Clojure, and I just wasn’t seeing it.”
- The auth token expired! What should we do?
- Why should the main loop have to deal with getting a new auth token?
- “The Twitter wrapper should be concerned with all of the warts and complexities of dealing with Twitter.”
- “What problems should bubble up, and which ones shouldn’t?”
- The wrapper should handle the retry.
- It’s like a kitchen in a restaurant. What are the steps of fulfilling an order? The customer doesn’t care.
- “There’s a side-effect: the freezer mutates.”
- The wrapper gets to worry about all the steps:
- turning the order into the specific request for the kitchen
- do the I/O to fetch and fulfill the request
- the “input transform” takes the mass of data and picks out the relevant parts
- the “internal” version is returned
- “Like all good metaphors, they stretch to the point where they break, like a rubber band.”
- Maybe avoid expired tokens by authenticating every time? Too much overhead.
- If the handle is mutable, then retry can just update the handle with the new token.
- A mutable handle does allow the wrapper to control the concern.
- The “handle” is the state of the wrapper. The term “handle” comes from I/O libraries.
- Instead of mutation, have the
searchcan catch an auth exception, retry, and return a new auth handle.
- Instead of
searchretrying, the fetcher can do it! Then it works for all kinds of requests.
- Better yet, leave fetch simple, and have a
fetch-with-retryfunction that uses
- Can have even more policy functions like,
- “Keep calm, and
- “I’m never going to miss another Clojure tweet. I’m going to read them all!”
Clojure in this episode: