Journal entry for
I’m still hard at work refactoring Reflex’ Spider implementation and greatly improving my understanding of what’s going on and seeing hints of how I can make a more grokkable version.
I’ve been doing this by constantly repeating the following:
- Inlining any function that’s only used once. In my experience splitting up imperative code into named procedures without their context, especially if they don’t capture a repeating pattern, is bad for grokking.
- Looking for repeating patterns. This is the slowest and most intuitive work, since code which does the same can be written in subtly different ways. And in imperative code it’s hard to deduce whether the order of statements matters.
- Bringing functions into the context in which they’re used. This makes patterns and dependencies more obvious.
Sometimes doing these steps will result in more lines of code because I’m using newlines to keep code readable. Big procedures and functions can sometimes make you miss the forest for the trees but I still feel it’s worth it. Re-reading, setting your font size really small, refactoring to bring function definitions as close to use site as possible using lexical scope all helped to find patterns which reduce the code size using meaningful, reusable, procedures.
This has been succesful so far, but at a certain point something else comes into play: thinking about the meaning of code:
- Is a certain function doing something conceptually similar to another?
- Could you express the shared meaning in a simple denotative semantics and using composition of semantic functions?
- Can you restructure the code similarly to how you wrote it compositionally?
Thought on dependencies & causality
I’m using Emacs’ LSP mode to find references to identifiers. These are listed in an “xref” buffer. I tried to refresh the buffer the usual way, but that’s not supported.
What would it take for something like a buffer to support “recreate me with the current state of the world”?