Ep 021: Mutate the Internet
Nate wants to tweet regularly, so he asks Clojure for some help.
- Problem: pre-author tweets so they can get posted automatically.
- Want to make a “full stack” application this time.
- Sounds complicated, what do we need?
- Database of tweets: text to tweet and timestamp when it should be tweeted.
- Frontend is a single-page application (SPA) that makes XHR (“AJAX”) requests to the backend.
- Needs to be able to wake up and post.
- Persistent process backend.
- We will not cover all these parts.
- “You have a problem, so you make a UI to solve your problem. Now you have 2 problems.” “More like 18 problems!”
- We will focus on logic interacting with Twitter.
- When should it post?
- How does it know if a tweet has been posted?
- What to do when Twitter returns an error?
- Overarching theme: how do you deal with side-effects in a functional way?
- Remember Ep 020: push side-effects and I/O to the edges.
- Easy to fetch “current” time, but that’s a side effect!
- “Just because it’s easy doesn’t mean it’s pure.”
- If you make time a parameter, all of a sudden you can mess with it!
- “If only real time was a parameter we could manipulate.”
- Lots of fun to be had in the upcoming episodes.
- ”‘Start with the data’ is something we’ve come to again and again. If you can model the data, that’s a very good place to start.”
Clojure in this episode: