Learning from esolangs: COMEHERE for better testing

Mike Samuel

Presented at the 12th Workshop on Live Programming (LIVE 2026). https://doi.org/10.5281/zenodo.24408792

Software testing can be hard. We've got IDEs, time travelling debuggers, and static analyzers but printf debugging is still a tried and true technique.

Imagine you're on the trail of a vexing bug; you suspect you know which function is responsible. Well, you can add debugging code, but you still have to get the program to go there; if the function is nested, there's no name main() can call to get there. And you can't just GOTO that code because it's harmful. Luckily the COMEFROM language solved that problem by allowing code at the destination to initiate a transfer of control.

What COMEFROM didn't solve was constructing the context necessary to figure out what's going on deep in the guts of your program. Instead, when you're hacking the suss function, just say COMEHERE:with().

I'm demoing a variant of JavaScript that adds COMEHERE to automatically drive control deep into a function to make interactive testing and debugging easy.

If you want your programming language to be easy to interactively debug or would like a semantics that allows turning the results of that interactive debugging into unit tests for implementation details deep inside nested functions that can specify inputs to outer function calls, then COME_ON_OVER to my talk!

https://mikesamuel.github.io/comehere/index.html

The headline

Encapsulation is important for maintainable systems. Otherwise you want developers speed-running Hyrum's law. But it can get in the way of interactive debugging because, for example, in PLs with closures, a nested function can't be referred to by name from the REPL making it hard to interactively investigate suspected problems with implementation details.

There's an important workflow that justifies loosening encapsulation: investigate bug, fix, and add tests to guard against regressions in future versions.

COMEHERE addresses this. A COMEHERE block can be placed inside a scope where a nested function is declared, and can specify the values it expects for the enclosing scopes. Then, when running interactively or as part of a test harness, rewrite rules modify control flow to cause the program to drive control to the COMEHERE block with the specified context (e.g. function inputs).

That supports two uses:

This talk also suggests ways that the former can inform the latter: how a REPL session or notebook that captures an investigation into a bug might be simplified into long-lived tests.

Building on the past

As mentioned in the abstract, the COMEFROM esolang inverts control flow. Code that initiates a transfer of control can appear inside the destination scope where there are names for the implementation details you want to investigate/debug/test.

This work draws inspiration from "Working Effectively with Legacy Code" by M. Feathers who defines a seam as a place where a program can be observed or, in a non-production context, altered without changing the behaviour of the system in production. COMEHERE's design adopts that goal of enabling investigation, debugging, and building test suites at seams with a feather-light touch.

Interactive debuggers with conditional breakpoints allow for pausing control and triggering effects. Some also allow starting a REPL session inside a scope, e.g. Python's PEP 553 breakpoint()s. This combination allows a developer who can engineer a call to an outer function to interactively investigate program elements encapsulated within an inner scope. It does not close the loop on guarding against future regressions. Time travelling debuggers make it easier to understand what happened prior to a bewildering state change but similarly do not close the loop on debugging. Visualization techniques like projection boxes and log visualizations help a developer make sense of a program but do not aid in interactive investigation of encapsulated subcomponents.

Aspect oriented programming (AOP) introduces a way to compose programs from separately specified fragments by naming "pointcuts" inside scopes that may be referenced outside those scopes and injecting behaviour at pointcuts. AOP does not address the problem of specifying context for surrounding functions or directing the program counter to the right place.

The E language for actor-style programs demoed a system for tests in documentation using a syntax that mirrors a REPL session, and serves as a great example of how a live debugging session might be pared down into long-lived regression tests.

Keeping a critical eye

This is an affordance for interactive program exploration and testing. It's not something you'd want to use in production code; the semantics are designed to have zero semantic footprint in production. It's also only useful for languages that encourage nesting, though the trend in modern languages seems to be towards closure capture.

Changing branch expressions to drive control flow can allow invalid program states. For example, if the code reads `if (x >= 0)` but the rewrite rules also allow executing the `if` clause when seeking a particular COMEHERE block, then expressions that reference `x` might observe negative `x`. For the specific use cases envisioned this can be a feature as well as a bug. Testing that subcomponents, like nested helper functions, behave sensibly even when the code that calls them fails to check preconditions, or will behave sensibly if the callers change to relax those preconditions, is a good practice for maintainable systems. But even if in production the COMEHERE blocks have zero semantic footprint, if the compiled binaries have extra branch conditions, that might confuse static analyzers like SAST tools that do flow-sensitive analyses.

The rewrite rules work for JavaScript are simple; it's event-loop concurrent so doing book-keeping via global state is viable. Global book-keeping state is not a viable strategy for dealing with re-entrancy in coroutines or parallelism due to threading. The rewrite rules can be adapted to account but it would require more work in the rewrite rules to keep the semantics identical when runtime introspection allows observing changes to function signatures.

There are some tradeoffs in semantics: the desire to run code that might initialize state vs the desire to skip flow control constructs that might not terminate, preventing driving control flow to the COMEHERE block.

Another potential complication is type narrowing. Adding extra clauses to control flow conditions can interfere with static type checking in languages like Typed Scheme, TypeScript, and Kotlin which use type predicates (aka guard expressions) to narrow types of common subexpressions based on how a branch condition that test runtime type information directs control flow.