It’s been a few weeks since I announced on /r/Clojure I was finished working on Mailfeed, a service that emails you whenever an RSS feed updates. A comment on that thread suggested that I share a little about the technologies I used and some of the pitfalls I hit during development. There’s a lot to talk about, so I thought I’d just drop a nice big list of all the major tech, services and libraries, then move on to some of the more interesting challenges.
If you’re writing a non-trivial application that will run in production, it’s usually a good idea to have some automated way to make sure that all the pieces are working together correctly. On a lot of projects this is going to mean integration tests. How granular these tests become will depend on your level of paranoia and how critical those integration points are to your application as a whole. In this post I’m going to use an example from a previous article and add some integration tests to ensure that we’re creating and updating accounts correctly.
I’ve been writing a few apps in my spare time, most notably Mailfeed, and I’ve developed a simple pattern whenever I need to pull data out of the database. This pattern could be be applied to any database you’re interacting with, but in this case I’ll be showing how I tend to do it with Postrges. I should say that none of this is groundbreaking stuff. If you’re an experienced developer then you’ll probably be saying “duh” a lot, but if your playing with Clojure and are struggling to come up with a good structure on how to do this kind of thing, then maybe this is something you could apply.
I’ve recently been exploring Datomic more seriously and have found myself jumping through the same hoops as I have in the past just to get things up and running. I’ve also encountered slight deficiencies in the documentation that I’ve had to re-investigate since the exploratory project I created was deleted quite a while ago. I’m tired of retracing my same steps over and over again so I thought I’d create a quick post with some of the basic steps to get setup and using Datomic in a Clojure application.
In the Clojure world, when you want to write a web app, you will almost certainly be using Ring. Ring is directly inspired by Rack, the defacto webserver abstraction for frameworks in Ruby. The two are conceptually very similar, but there are some slight differences (aside from language) that might be interesting to highlight. I won’t be going too in depth with this post, and will focus instead on the basics of using Rack and Ring.
Let’s look at the different flavors of function composition in Clojure.
In my last post I built a simple text manipulation widget with React. I recommend reading through that post first, before this one. As promised, I’ve built the same widget in Om, a ClojureScript library that sits on top of React.
React is a new-ish library from Facebook/Instagram that is designed to make building user interfaces easy. I thought it would be fun to build a basic example in React, and then contrast it with the same example in Om. First let’s setup the page where our example will live. We’re going to want a container for the React root component, which we’ll give the id app, and we’ll include the React library and the JSX transformer.
Getting started with Clojurescript can be tough if you’ve never done it before, and once you do you might find yourself running through the same steps to get new projects into a structure that makes sense. In either case, the solution is to use a Leiningen template. My goal here is to show how easy it can be to create one of your own. Most templates are built for Clojure, but we’ll be creating one for Clojurescript.
This commit was pushed up to Clojurescript core recently, adding a new
specify. This means we can now have instance-level implementations of
protocols on specific values: