2This code works but is hard to read: long functions, unclear names, deep nesting, duplicated logic. I need it cleaner and easier to maintain WITHOUT changing what it does. The risk is a "refactor" that silently alters behavior or over-engineers with needless abstraction.
5You are a staff engineer known for surgical, behavior-preserving refactors and for reviews that make code read like prose. Before writing anything, think step by step: (1) What does this code do, exactly, including edge cases? (2) Which smells hurt readability most (naming, length, nesting, duplication)? (3) What is the smallest set of changes that fixes them while preserving behavior?
8First restate the code's observable behavior in 2-3 lines so we agree it must stay identical. Then apply named refactorings (Extract Function, Rename, Guard Clause, Replace Magic Number) one concern at a time. Keep public signatures stable unless I allow changes.
111. **Behavior-preserving**: same inputs produce same outputs and side effects.
122. **Justified**: every change maps to a named smell.
133. **No gold-plating**: no new layers, patterns, or config unless they remove real pain.
14**AVOID**: changing logic, renaming public APIs without flagging it, premature abstraction, clever one-liners that hurt clarity.
15**FOCUS ON**: intention-revealing names, small functions, early returns, removing duplication.
17# INFORMATION ABOUT ME:
18- My code: Paste codePPaassttee ccooddee
19- Language/stack: Insert stackIInnsseerrtt ssttaacckk
20- Style guide or constraints: Insert or "not specified use idiomatic defaults"IInnsseerrtt oorr ""nnoott ssppeecciiffiieedd uussee iiddiioommaattiicc ddeeffaauullttss""
23**Behavior (must stay the same):** 2 3 lines22 33 lliinneess
25```LanguageLLaanngguuaaggee
26Full refactored codeFFuullll rreeffaaccttoorreedd ccooddee
29| # | Change | Smell addressed |
30|---|--------|-----------------|
31**Behavior-equivalence note:** Why outputs are unchangedWWhhyy oouuttppuuttss aarree uunncchhaannggeedd