Menu

1 / 2

I Asked AI to 'Refactor This Nicely' and Got Unwanted Decimals and Dataclasses

DEV Community·Ken Imoto·7 months ago
#hVoUcmAc
#ai#refactoring#python#total#code
Reading 0:00
15s threshold

I handed a 40-line order processing function to Claude Code and said "refactor this nicely."

What came back: Decimal class, dataclasses, logging module, full type hints, and a Strategy pattern. 120 lines. I asked for none of it.

Does it work? Yes. Is it readable? Yes. Will the reviewer say "do I really have to review all of this?" Also yes. And the SQL injection fix I actually needed? Buried somewhere in the diff.

So I ran an experiment. Same code. Two prompts: vague vs. specific. Here's what happened.

The Experiment

Target Code

A 40-line function with 5 intentional problems:

def process_order ( order_data ): total = 0 for item in order_data [ ' items ' ]: price = item [ ' price ' ] qty = item [ ' quantity ' ] if item .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.