Strange Loops and Self Authoring Code

14 September, 2020
3 min read

I recently started reading Godel Escher Bach: An Eternal Golden Braid which introduced me to the concept of strange loops. Through Bach's Canon a 2 per Tonos, M.C. Escher's illustrations and Godel's incompleteness, Douglas Hofstadter connects the concepts of tangled hierarchies and self referential systems across domains.

An Electro-Mechanical Offering

I've always thought these kinds of systems were beautiful and in high-school I "invented" a water purification system which would power itself with the electrons released during reverse osmosis, my hopes at a nobel prize however were dashed by the conservation law.

I later encountered feedback loops in my first year electric circuits course via operational amplifiers. Normally in electric circuits when you connect a systems input to it's output things tend to blow-up, so op-amps ability to resist explosion (most of the time) seemed to be quite novel.

non-inverting op-amp

I'd later encounter these seemingly paradoxical systems throughout my studies with flip-flops in sequential logic circuits, non-causal systems analysis in signal processing and later recurrent neural networks.

A Volatile and Persistent Reaction

Fast forward a bit and my team and I had created a chat application for a hackathon at work and astonishingly we had a seamless demo of multiple clients connecting to the server, joining chat rooms and chatting in real-time. However when we had to present our code it was revealed that our "database" was actually a set of in-memory arrays whose data would disappear as soon as the server was switched off, now in our defence in-memory storage is very fast it just doesn't actually do well on the storage criteria.

Now this was good enough for the hackathon and the logical solution going forward would be to spin-up an actual database for data persistence, but this is boring, non-loopy, un-strange and runs very little risk of blowing up.

So over a year after the hackathon inspiration struck, the idea — an in-memory data store that would be persistent by actually writing values into it's own source code. This idea ticks two important boxes because A) it is so bad it's good and B) it has this self-referential tangled hierarchy. While it's not as beautiful as a Bach composition or an Escher illustration here's my little strange loop.

you can try it for yourself over here 👉 https://github.com/phxtho/incode-db