Workflow for Partitioning Complexity

I can’t handle lots of complexity at once. If I can change simple parts of complex programs, then I can still make changes. Complex changes paralyze me. - Kent Beck link

# step 0: the example code

In an experimental Smalltalk virtual machine, library, and programming environment, I just-added references to variables to the abstract syntax tree:

function generate_on(node, writer) ... case VariableNode: writer.push_argument(0) break

# step 1: constant

Extract the constant 0. (Bonus points if you recognized this as complexity partitioning)

case VariableNode: let index = 0 writer.push_argument(index) break

And introduce a hard-coded table to look up the name of the node.

case VariableNode: let name = get(node, 'name') let symbols = { 'ifTrueBlock' : 0 } let index = symbols[name] writer.push_argument(index) break

# step 2: migrate

Move the hard-coded symbol table.

function generate_method() ... let symbols = { 'ifTrueBlock' : 0 } generate_on(node, writer, symbols) function generate_on(node, writer, symbols) ... case VariableNode: let name = get(node, 'name') let index = symbols[name] writer.push_argument(index) break

# step 3: compute

Compute the symbols instead

function generate_method() ... let symbols = {} for (symbol, index in arguments) symbols[symbol] = index generate_on(node, writer, symbols)

# The Workflow as a Whole

At each step we’re changing one thing at a time but we had to modify our workflow to make this possible. There is a tradeoff between the cost of adding steps to a workflow (in this case replacing the hard-coded symbol table with a computed one) and the expected cost of mistakes (and for me the expected cost of staring out the window because I’m overloaded).

Constant/migrate/compute works at various scales. Here we’ve used it to partition complexity between functions. We can also use it to partition complexity between classes, modules, or services.

An additional bonus of the constant/migrate/compute workflow is that it lets us work concrete to abstract. This matches how my brain works (YMMV).

Try this workflow out, observe the effects it has on your thinking and emotions, and modify it to suit. You will be building the metaskill of observing and adapting your own workflow.

.

TDD By Example

No surprise this example reads like an excerpt from TDD By Example.

TDD By Example illustrate the rhythm. Speaking of rhythm: see also Rhythm Autonomy Mastery Purpose Safety.