Show Blast Radius

Show Blast Radius pictures who a purity change would reach before you make it. Here announce() is pure but calls shout(), which is not (E08130); morningBriefing() and eveningBriefing() are both pure callers of announce(), in two different files - read the code. To play it in the IDE: Help > Lessons > Understanding a codebase…, or ek9 -ide -lesson blast-radius.

The EK9 IDE as the lesson opens: the code to read and, in the Hovers panel, its error explained

Start from

The code the lesson starts from: copy it into a file of your own and follow the steps.

core.ek9

#!ek9
defines module lesson.broadcast

  defines function

    shout()
      -> message as String
      <- rtn as String: message.upperCase()

    announce() as pure
      -> message as String
      <- rtn as String: shout(message)

//EOF

morning.ek9

#!ek9
defines module lesson.broadcast

  defines function

    morningBriefing() as pure
      -> name as String
      <- rtn as String: announce(`Morning, ${name}`)

//EOF

evening.ek9

#!ek9
defines module lesson.broadcast

  defines function

    eveningBriefing() as pure
      -> name as String
      <- rtn as String: announce(`Evening, ${name}`)

//EOF

Step 1: Where the change starts

Put the caret on shout(message), on line 12 - where the compiler flagged it.

The EK9 IDE once this is done: Put the caret on shout(message), on line 12 - where the compiler flagged it

Step 2: Show Blast Radius

Right-click it - or choose Refactor > Refactor This… - and choose Show Blast Radius (purity impact).

The EK9 IDE once this is done: Right-click it - or choose Refactor > Refactor This… - and choose Show Blast Radius (purity impact)

Step 3: The ripple

The Fix dropdown starts at Drop pure from announce(). announce() sits at the centre, ▼ shout() to its right (the non-pure callee - what Make callee pure would change), and ▲ morningBriefing() and eveningBriefing() to its left (the pure callers that break if pure is dropped from announce()) - a would-fail verdict, because dropping it ripples to two files.

Step 4: The other direction

Choose Make callee pure in the Fix dropdown - making shout() pure, instead of announce() not. Apply turns from disabled to enabled: nothing else breaks, so this direction is ready.

The EK9 IDE once this is done: Choose Make callee pure in the Fix dropdown - making shout() pure, instead of announce() not

The result

That is Show Blast Radius: removing pure from announce() would break 2 callers in 2 files - morningBriefing() and eveningBriefing() - so EK9 refuses it outright for this direction; adding pure to shout() instead breaks nothing, and is the one Apply offers. Fix Purity Contract plays that Apply, from the same pane, on a simpler override with no choice to make. The same picture, but for a function's SIGNATURE rather than its purity, opens from the Change Signature preview's Visualise impact button; AI assistants get this purity picture as data from ek9_query_purity_impact, and the signature one from ek9_query_signature_impact.

Where this lesson comes from