Hey Folks! It’s a new site. If you see bad links or odd behavior, please contact me right away. Thanks! – GeePaw
 Home  Home  hom  Meet with GeePaw  Meet with GeePaw  mee  Work with GeePaw  Work with GeePaw  wor  Who's GeePaw  Who's GeePaw  who  Blog  Blog  blo  Contact  Contact  con

The Thinking Knee In Coding Practice

 1. January 2018

we’ve spent some time on the thinking-knee, but i’m not quite done with it yet. let’s narrow our focus for a minute, to matters strictly around code & coding.

programmers have been thinking directly & indirectly about ways to evade or at least mitigate the effect of the non-linear thinking knee more or less forever.

dijkstra’s famout short paper, “Go To Statement Considered Harmful”, from ‘68, is an early example. he doesn’t invoke the knee explicitly, but the harm he’s speaking of is expressly that it makes it hard for humans to think about the code. ”structured programming,” the movement surrounding this paper, is almost entirely an effort to start minimizing and organizing the pieces of code we have to think about.

tho some of its tenets have been softened over the years, the gist of structured programming is nearly invisible to us: it is the air we breathe. most of us take single-entry (not so much single-exit) named functions taking parameters & returning values entirely for granted.

so people who theorize about the human act of coding have been wrestling with the thinking knee in a variety of ways for a long time. the agilists have forwarded this movement, but we didn’t start it and we’re not done with it yet.

not all such efforts have been successful by the way, and one illustration of this might actually help us here: simonyi’s now much-derided hungarian notation. (for those who didn’t suffer through this, hungarian notation is the practice of pre-pending type info to variable names, so iCount is an integer, afPoints an array of floats, or such-like.) the impulse – help geeks think about their code – was good. the belief that providing more info about a variable whose declaration was very far away, not so good.

from a thinking knee perspective, hungarian notation says/does nothing about the piece count, it just attaches extra info to each piece. the result may have been slightly net-positive, tho that’s debatable. in the end, hungarian was discarded because it wasn’t free and it didn’t attack the main problem: piece count itself.

so how do we attack the piece count to keep from loading ourselves past the thinking knee? (speaking strictly about coding for today, we’ll zoom back out later.)

in miller’s even more famous paper, “The Magical Number Seven Plus Or Minus Two”  he posits that the human thinking knee happens when we get up between 5 and 9 pieces.

(aside #1: you really ought to read this paper, as it is not only fascinating in its conclusions, but is both charming & rather funny. it puts to rest thoroughly the idea that science writing can’t be great writing. aside #2: most modern psychologists would tell you that miller was wrong: the 60 years since have produced hundreds of experiments suggesting he over-estimated, and the real value is between 4 and 7 pieces.)

but if the thinking knee happens around 7 pieces, how do human thinkers do anything? how do programmers write programs containing literally hundreds of thousands of pieces?

the trick is called “chunking”. there are a lot of subtleties and sub-tricks involved, but the colloquial version looks like this: “put pieces in boxes. when you’re in the box, only think about it’s contained pieces. when you’re out, treat the whole box as one piece. chunking works. in some circumstances, it works very well, in others, less so. one way to see the last 40 years of coding theory is to see it as the working out of more & better ways to chunk things.

this is not an “agile” thing, not yet. single-entry structured functions are chunks. objects are chunks. the horizontal layers of layered architecture, the vertical stripes of microservices, the package/module/namespace stuff in most modern languages: all chunk facilitation. they are all about cheating the thinking knee by using chunks to get the piece count low enough that we can think effectively.

so agile coding practice isn’t an abrupt departure from the last decades of mainstream coding practice, but a continuation and extension of it. it is the latest of many waves whose focus is the thinking knee.

so much focus on names? strong names facilitate chunking. SRP and most of SOLID? clean boundaries between chunks.

what even is refactoring? “factor” is just another name for chunk. refactoring is rearranging chunks without changing function. there’s no possible reason for it but to facilitate chunking.

the microtests we prefer in TDD? the way we test interactively, test-code-test-code-test-code? directly about keeping piece counts small. (hard-TDD’ers, like myself, would add that TDD’s view of tests & testability as first-class participants in design is actually itself a way to encourage if not force good chunking.)

so. where are we?

some problems are non-linear. action cost goes up faster than piece count, sometimes so much faster it creates knees that we very much want to avoid. human thinking has such a knee. we use chunking to sidestep or mitigate its effects. coding practice has been about keeping programmers below that knee for at least 4 decades through facilitating that chunking and agile coding practice is in many ways an extension and retrenchment of this movement to ease the chunking process.

we’re almost there, and i’m relieved cuz i’m ready to be done with this topic for a while, but there’s one more piece, for next time: how does agile practice address the thinking knee in contexts around and beyond coding itself?