Over the last few weeks, we’ve been cleaning up the dependencies in our Swift Talk backend. Now that we’re done, we finally feel like we’re on top of the code base again. No more dark, dusty corners!
In this post, we’ll outline how the code base has developed over time, and the changes we’ve made to clean it up.
We started developing the Swift Talk backend almost three and a half years ago. To begin with, we hired a contractor to build the site using Ruby on Rails. After we launched, we continued to make small changes ourselves, and hire other contractors for larger things.
.js files as before, just from our Swift server.
A few things bothered us about the state of this code base:
Some of the Swift dependencies felt unnecessary, given the little code it would take us to directly interface with the underlying libraries.
With regard to the Swift dependencies, we ended up writing our own lightweight wrapper around libpq, similar to the wrapper we demonstrated on Swift Talk. Our wrapper is approximately 300 lines of code, almost half of which are straightforward mechanical conversions between Swift types and their representations in PostgreSQL. We’re happy to maintain this small piece of code against a mature library like libpq ourselves. The benefit is that we can easily fix warnings that arise with new Swift versions, fix bugs as we encounter them, or make changes to the API so that it better suits our needs.
We also removed our dependency on BlueCryptor, a Swift wrapper around CommonCrypto on macOS and libcrypto on Linux. Since we were only using it to create md5 hashes for our assets, we wrote our own md5 wrapper around the native crypto libraries, with approximately 30 lines of code.
Before, we used Perfect-XML to parse XML on Linux, as Foundation’s XML parsing gave us strange crashes. In recent releases, these issues have been fixed, and we were able to drop the dependency and use Foundation instead.
We took a long hard look at the CSS, and also managed to remove almost all dependencies.
If you’d like to check out the backend, the source code is on GitHub.