APromptAura
0

Turn a god function into composable, testable units

auto-checked, 4 days old
AauraNovice

The prompt

0 copies
I have a function that has grown too large and does too many things. Refactor it into smaller, single-responsibility functions or classes, following these constraints: 1. Preserve the exact external behavior and public signature unless I say otherwise. 2. Extract pure logic (no I/O, no side effects) into its own functions first, so they can be unit tested without mocks. 3. Name each extracted piece for what it does, not how it does it. 4. Show the before/after side by side for the riskiest extracted piece, with a one-line note on why it is now safer to change. 5. List any behavior that is ambiguous in the original code (e.g. unclear error handling, implicit ordering dependencies) that I should confirm before shipping this refactor. 6. Do not introduce new dependencies or design patterns beyond what the language's standard idioms support. Language/framework: language Function to refactor: code What it's used for / calling context: context

Run it in your model, then come back and report whether it worked, including the model and version.

Where it has been run

People and our automated sweep are counted separately. Only the People column is someone vouching for this prompt.

ModelVersionPeopleBrokeAutoLast
ClaudeHaiku 4.5001/14 days ago

Example output

Extracted 4 units from the 140-line `process_order`: `validate_order_payload` (pure), `compute_line_item_totals` (pure), `apply_discount_rules` (pure), and `persist_and_notify` (I/O only). Before/after for `apply_discount_rules`: Before: discount logic was interleaved with tax calculation and a DB write, so testing 'does a 10% coupon stack with a loyalty discount' required a live database. After: `apply_discount_rules(items, coupon, loyalty_tier) -> list[LineItem]` is pure, so the stacking behavior can be asserted with plain dicts in under a millisecond. Ambiguities to confirm: original code silently ignores a coupon if `loyalty_tier` is None instead of raising, unclear if that was intentional; also the tax calculation reads a global `TAX_RATE` that isn't passed explicitly, which I made an explicit parameter, confirm no other caller depends on the global being mutated at runtime.

0 comments

Sign in to comment or report what this prompt did for you.

Sign in

No comments yet. Run the prompt and report what you got.