Generalistic writings from @vlnn
20 May 2024

THE Solution to the REPL snippets (using Emacs ofc)

Miro Bezjak wrote an interesting post called What to Do With Evaluated REPL Expressions?. The problem he describes is actually a bit different from the one I thought of when saw the title: it’s not about re-using evaluation results in the REPL (which is not really possible without re-evaluation or using weird numbering acces – as far as I know). No, it’s really about the expressions that should not go into the the released code, but the one the developer uses during the development – small chunks of the code with ops-tasks, small checks, calls to the external systems etc. Miro suggests to create the out-of-classpath user directory for every project developer, and create a common place for all those code snippets called everything.clj or something like that. This file should be committed to the repo (thus shared and easily referenced between the developers), but not become the part of “official code” (hopefully not even being compiled while release process).

I like the approach but I dislike several little problems that come with it. First of all, “operational” snippets are often bound to the exact configuration – hostnames, port numbers etc. Even secrets! Thus, you shouldn’t share it as is: they should either become some developer environment script, or go away with the repl history. Don’t encourage other users look into the pie if you’re not sure it is the same pie you’re both having.

But my main concern is that the problem is being resolved on wrong level. There are special programs that are perfect for using and managing snippets called text editors. Every text editor (and hopefully any IDE) provide search, copy and paste capability. Emacs even has a built-in buffer that can be used specifically for that reason called scratch buffer: something written there for the moment, edited, ran, saved somewhere else… and then scratched out as new tasks are coming. You may even configure project-related scratch buffer that will not erase its text after restart of Emacs. So for the development itself you may safely use scratch buffer (or anything having same function in your editor of choice). But what if you want to reuse it? Create either a devenv script or yasnippet file. What if you want to share it with colleagues? Use gist (or even better internal wiki). In that way when the code will change the behaviour (due to your or your colleauges’ work on the code or infrastructure) the snippet will not be incorrectly bound to the updated code. The script is outdated? Well, update it on separate PR, or let someone else do it. Wiki is outdated? Fix it on the spot. The idea is that the production code should not be contaminated with the operational code – or it should be a well-designed part of the code.

Tags: discussion repl clojure emacs
Other posts
Creative Commons License
bastibe.de by Bastian Bechtold is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.