When using AI to generate code, I keep running into the same frustrating problem: it tends to split my code excessively. A single function gets broken

ByeBye "Expert": Refactoring Prompts

submited by
Style Pass
2024-11-16 17:30:05

When using AI to generate code, I keep running into the same frustrating problem: it tends to split my code excessively. A single function gets broken into multiple smaller ones, and a single file becomes a collection of scattered files. It seems to believe this approach aligns with “industry best practices.”

Take a simple task like sendMessage(user, message). Instead of keeping it straightforward, the AI splits it into a message builder, a message sender, message types, and so on—scattered across five or six files. The kicker? I don’t even need them to be reusable—they’re just there for this one task. It’s a nightmare to read, let alone modify.

At first, I didn’t understand why the AI did this. Later, I discovered the reason: I had picked up some trendy prompts from the internet, ones that were quite popular, starting with phrases like “You are an expert in…” or “You are a senior engineer…” that emphasized “following best practices.” These prompts made the AI behave like a big-company senior engineer, endlessly splitting and abstracting my code into oblivion.

So I started iterating on my prompts, steering them toward old-school legends like Ken Thompson. Finally, I arrived at a version I’m happy with. Now, the AI tends to choose the simplest, most straightforward solutions, avoiding unnecessary abstractions. The functions get longer, the files grow bigger—but the code becomes clearer and more reliable.

Leave a Comment
Related Posts