6. Method coding advice

Six things this study would tell you to do differently, each paid for by something that actually happened in it.

6.1 Ask what every column was computed from, and enforce the answer in code

The single most transferable lesson. A column is evidence about a quantity only if it was measured independently of it. Table 2's distances were computed from the velocities with the very constant under test; using them would have produced a confident, well-formatted tautology.

The fix is not a comment. Put the exclusion at the one door every cell must pass through, and then have the consumer assert it independently:

TABLE2_FORBIDDEN_COLUMNS = ("r_mpc", "vs_kms", "M_t")

def load_block(name, *, echo=True):
    ...
    # Drop by what was REQUESTED, not by what was served: under a dry run the
    # rows come from the development block, but the cell being rehearsed is the
    # sealed one and its column contract must be rehearsed too.
    if name == BLOCK_TABLE2:
        block = block.drop(columns=[c for c in TABLE2_FORBIDDEN_COLUMNS
                                    if c in block.columns])
# ...and in the cell, an independent assertion that the door did its job:
leaked = [c for c in TABLE2_FORBIDDEN_COLUMNS if c in block.columns]
if leaked:
    raise RuntimeError(f"forbidden columns reached the sealed cell: {leaked}")

Both guards were needed. The first rehearsal failed precisely because the library dropped by the served block while the cell asserted on the requested one — a check at the door and a check at the consumer is what turned a silent shape mismatch into a loud, cheap failure.

6.2 Read the rehearsal's numbers, not its exit code

The mandatory sealed dry-run saved this study twice. The second time it passed: exit 0, a well-formed block, a pinned table — carrying an inverted rescale that would have recorded a refutation on 2680.495911 and spent the track's only access. The bug was one character of direction:

# WRONG - sends the fits to ~2570 instead of ~70
r_rescaled = r / factor

# RIGHT - Hubble's distances were too SMALL, so correcting the ladder MULTIPLIES
# them, which divides the slope:  v = K r = (K/f)(f r)
r_rescaled = r * factor

A sealed run can be wrong without crashing. Budget a minute to read what the rehearsal printed and check it against what you expected before you spend the access.

6.3 When the predictor is the noisy variable, report both regressions

One number from v ~ r is a lower bound, not an estimate. Reporting the inverse fit beside it costs one function and, here, changes the headline by a factor of 1.603771. Pair them on common random numbers or the difference carries independent noise and looks less decisive than it is:

def paired_bootstrap_k(r, v, *, n_boot, seed, estimators):
    """Several estimators on the SAME resamples - common random numbers.

    Drawing twice would add independent noise to the difference and inflate
    its standard error.
    """
    rng = np.random.default_rng(seed)
    draws = rng.integers(0, r.size, size=(int(n_boot), r.size))
    R, V = r[draws], v[draws]
    return {name: k_of_batch(R, V, name) for name in estimators}

If the error ratio is known, use an errors-in-variables fit. If it is not — as here, where the paper prints neither error — say so and give the bracket rather than inventing the ratio. This study declined a Deming fit for exactly that reason and recorded the refusal.

6.4 A floor for a proportion needs more than its observed spread

Five seed blocks put coverage in a band of 0.007 and produced a minimum_delta of 0.0060663; the next block landed at 0.911, outside every one of them. A small-k spread of a Monte-Carlo proportion is a lower bound on that proportion's variability. Size the floor against the binomial standard error too, or accept that the floor is optimistic and say so where the number is used.

6.5 Make a pinned table deterministic on purpose

Ten of ten cells reproduced with difference exactly 0, which is not luck. One writer, fixed column order, fixed float formatting, LF endings, no index — and it does not write at all under the smoke flag, so the sanctioned pre-run check leaves the tree clean for the notary:

def write_table(relative_path, columns, rows, *, float_format="%.6f"):
    path = study_dir() / relative_path
    frame = pd.DataFrame(list(rows), columns=list(columns))
    text = frame.to_csv(index=False, sep="\t",
                        float_format=float_format, lineterminator="\n")
    if os.environ.get("KLEIN_SMOKE") == "1":
        return path              # a smoke run writes no sidecars
    path.parent.mkdir(parents=True, exist_ok=True)
    path.write_text(text, encoding="utf-8", newline="")
    return path

6.6 A prospective lock is a lock — and the tempting repair is not

The analyst had read every sealed row before the contract existed. The instinct is to recover a "fresh" holdout by bootstrapping a block out of the rows already seen. Reject it. Resampling rows an analyst has seen creates no new information: every resample is a function of the same bytes, so the "holdout" is a rearrangement of the training set wearing holdout vocabulary.

What protects a sealed comparison is not the analyst's ignorance — which cannot be restored — but that the analysis was fixed before the comparison ran and the comparison was made once. Write the statistic, the columns, the constant it takes and the tolerance into the contract, let the gate hash them, spend the access once. Then say "locked before", not "blind".

6.7 The sealed cell, in full

Below is the actual entrypoint that spent this study's reproduction seal, included as it was at its candidate commit 34107cee. On a registered track the mutable surface is restored after every run, so what ran lives in the candidate commits rather than in the working tree; the builder reads the bytes from that commit itself, and the provenance line above the listing names the run, the commit and the hash (git show 34107cee:studies/10-hubble-1929-replication/analyze.py reproduces it). Note the three things it does before it computes anything: it reads its constant from a pinned table rather than refitting, it goes through the single data door, and it re-asserts the column exclusion itself.