question

John Doe

John Doeasked a question

17 hours ago

When should I refactor a working function instead of leaving it alone?

I have code that works, but it is getting harder to understand. How do I know when cleanup is worth the risk?

1

2 answers
closed
You need to log in to answer this question.log in
Alex Smith

Alex Smithanswered

•

17 hours ago

Leave it alone if the code is stable, isolated, and rarely touched. Refactor when repeated edits keep making you reread the same confusing branches.

2

Accepted answer
Jane Doe

Jane Doeanswered

•

17 hours ago

Refactor when the function has more than one reason to change or when adding the next feature requires copying logic. Keep the behavior covered before you move code around.

0