Follow

I really feel like people don't emphasize spread minimization enough when programming. Here the "spread" of something is the literal distances between elements in that thing, or the distances between things. In programming its generally like the distance between two functions when one calls the other. One example where minimizing spread is obvious: say you have a function `f` that calls a helper function `g`, and `g` is only called by `f`. The most obvious place to put `g` is right next to `f`. In languages where you can put functions in any order, it generally doesn't make much sense to put, for example, `f` at the bottom of a file, and `g` at the top of the file

Of course the ultimate determiner where things should go is where they will be the most comprehensible by a programmer trying to understand the code. And minimizing spread is probably one way to do that (its at least correlated with it). In the best case everything you're looking at can fit on the screen at once, which allows you to more quickly read between them, and necessarily means minimized spread

There's also another kind of spread that I'll call control flow spread which is like how far the control flow bounces around your lines and files while the program is actually executing. If every other step your debugger is opening another file, then your program's control flow spread is probably pretty high. That's not necessarily a bad thing, but rather its probably like its good-v-badness is in the same category as abstraction's. An abstraction is generally very helpful because it generally encompasses more behaviors and its more comprehensible when the abstracted component is looked at in isolation, but (at least in my experience) it tends to make it harder to reason about the system as a whole, or at least the interactions between abstract entities in the system, because mental concretization of abstractions is effortful

As so often seems the case, spread minimization is competing with other principles such as minimizing code duplication. If you choose to take some duplicated code and put it into its own function, you've probably just introduced both textual and control flow spread, along with increased abstraction. Again, those aren't necessarily bad things, but they do have consequences

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.