MojaCode

A personal studio
for AI coding.

On the deskIndex

05 / Refactor notebook

Change the shape. Preserve the promise.

A refactor should make code easier to work with while retaining its observable behavior. Start by writing down what must remain true, including awkward existing cases.

Establish the current behavior

Read the callers and tests before selecting an abstraction. Capture representative inputs and outputs, error handling, and relevant side effects. If coverage is thin, add focused characterization cases for the behavior at risk. Avoid locking in every incidental detail; preserve the contract that callers actually rely on.

Choose one structural concern

Extract a repeated transformation, reduce a tangled branch, or move a well-defined responsibility. Ask the assistant to explain why that step reduces complexity. Keep feature changes separate so a reviewer can distinguish a structural improvement from a new behavior. Do not introduce a generic framework for a pattern that appears only once.

Read the diff as a caller

Check public signatures, ordering, failure modes, and resource handling. Run the relevant tests and inspect their results. A smaller file is not automatically a simpler system if the logic has become harder to follow across modules. End with a short explanation of the new responsibility boundary and the evidence that behavior stayed stable.

A refactor commission

Inspect the exporter and its callers. Propose one structural simplification that preserves output ordering, public signatures, and error behavior. Identify focused checks before making changes. Keep feature work outside this refactor.
Continue the practiceReview practice