DEV Community

Mahiro Hirakawa
Mahiro Hirakawa

Posted on

The measurement in my permanent log was a string literal

This line is in a record I cannot edit, because the record is append-only and that is the point of it:

OK_ATOMS atoms=0 top=0 bot=0
Enter fullscreen mode Exit fullscreen mode

It reads as a measurement that found nothing. It is a placeholder. The three zeros are characters in the source file, written while the real counter was still being built, and the line was emitted unconditionally every run.

Nothing counted anything. There is no code path behind those numbers.

Why it survived

Because it is well formed.

A placeholder that says TODO gets noticed. A placeholder that says atoms=0 top=0 bot=0 does not, because it has the shape of every other line in the file: a name, three key-value pairs, plausible values. It sorts correctly. It parses. Anything downstream that reads the log gets a valid record with a defensible value in it.

And zero is the most convincing possible placeholder, because zero is what a real run legitimately produces when there is nothing to count. There was nothing to count at the time it was written. Then there was something to count, and the line did not change.

what a reader sees what produced it
OK_ATOMS atoms=0 top=0 bot=0 a string literal
a run that examined the corpus and found it empty nothing examined anything

Those two are indistinguishable from the log alone, and the log is what everything downstream believes.

It reached the permanent record

That is the part that turned an embarrassing constant into a real problem. The line was appended to an append-only journal, so it cannot be deleted, and the correct repair is a second record that supersedes it rather than a quiet edit.

Which is right, and it is also the mechanism working exactly as designed, catching its owner. A record you can silently fix is a record that never tells you that you fooled yourself.

The rule

A placeholder is never a print.

If a line is going to look like a measurement, it has to come from one. Until the counter exists, the honest emission is the one that cannot be mistaken for a result:

- console.log('OK_ATOMS atoms=0 top=0 bot=0');
+ throw new Error('UNIMPLEMENTED: atoms census not wired');
Enter fullscreen mode Exit fullscreen mode

Loud, unmistakable, and impossible to leave in by accident. The scaffolding version is comfortable exactly because it lets the build stay green while the work is unfinished, and that comfort is the whole cost.

The weaker version of the same rule, for cases where the build genuinely has to run: emit a named third value rather than a plausible number.

UNTESTABLE_ATOMS reason=census_not_wired
Enter fullscreen mode Exit fullscreen mode

Nothing downstream can average that, chart it, or read it as evidence of an empty corpus.

How I would find the others

Grep your own log vocabulary against your source. Any print whose numeric fields are literals in the emitting file, rather than variables, is a candidate:

$ # print statements whose values contain no interpolation
$ ... | wc -l
Enter fullscreen mode Exit fullscreen mode

The ones that come back are not all wrong. Some are genuinely constant. But every one of them is a line that will keep saying the same thing forever, and the question worth asking of each is: if the underlying quantity changed tomorrow, would this line change with it?

If the answer is no, it is not a measurement. It is a caption.

Top comments (0)