Refining Business Logic Through Dialogue

"Create a simple To-Do List app."
GPT-4 can now handle a request like this in 30 seconds. However, the problems we face in the field are rarely this simple.
"A user changes their subscription plan from 'Basic ($10)' to 'Pro ($30)' in the middle of the month. Calculate the prorated difference for the remaining days, charge that amount, maintain the existing billing cycle, and if the payment fails, revert to the existing plan."
There is no AI (yet) that can perfectly implement such complex business requirements with a single prompt. If you force it, it will merely spit out code that looks plausible on the surface but is riddled with bugs.
When implementing complex features, what you need is not "One-Shot Coding," but obsessive dialogue (Ping-Pong) with the AI. Today, we will explore how to design robust business logic using the Chain of Thought (CoT) technique to maximize the AI's reasoning capabilities.
1. Do Not Write Code First (Pseudo-code First)
Opening the IDE immediately when facing a complex problem is a habit of junior developers. Seniors start by drawing on a whiteboard. Collaboration with AI is no different. If you immediately say, "Write this in Python," the AI becomes obsessed with getting the syntax right and loses track of the logic.
First, reach a consensus on the flow of logic using natural language or Pseudo-code.
π¬ Dialogue Example: First-Come-First-Served Coupon System
Developer:
"I'm going to build a feature that issues coupons to the first 100 people. Concurrency issues are key. We will use Redis, but don't write the code yet. Just explain the logic Flow step-by-step."
AI (CoT Activation):
Developer (Critique & Refine):
"Wait. The Gap between steps 2 and 3 will cause a Race Condition. If another request comes in between the GET and INCR, more than 100 coupons could be issued. Modify the logic to use the fact that Redis INCR is Atomic, or use a Lua Script."
This process is CoT. We haven't written a single line of code, but we've already caught the most fatal bug in advance.
2. Torment the AI with "Edge Cases"
Once the big picture of the logic is drawn, you need to push the AI to its limits. AI tends to default to the "Happy Path" (scenarios where everything succeeds without issues).
Your job is to become the Devil's Advocate.
π The Obsessive Question List (Prompting)
When you ask these questions, the AI will apologize ("Ah, I missed that part.") and start adding Defensive Code to the logic. As this Tiki-Taka repeats, the logic becomes solid.
3. Implementation: Translation Comes Later
Once the consensus on logic and exception handling is finished, converting it into actual code is merely "translation." Only then do you ask for code in a specific language.
"Based on the logic we agreed upon above (Redis control using Lua Script + DB transaction rollback handling), write the actual service code using Node.js and TypeORM."
The code produced this way is likely to be "Senior-level code" that reflects far more considerations than if you had written it alone.
4. Real-World Scenario: Complex Subscription Proration
Let's assume you are building the "Subscription Upgrade" logic, which is the biggest headache in SaaS development, with AI.
Conclusion: The Developer is a "Director," Not a "Coder"
In this process, you barely did any typing yourself. Instead, you asked, criticized, and verified.
In the AI era, development capability depends not on "how fast you type code," but on "how logically you lead the AI so it doesn't write stupid code."
Trust your AI partner. But doubt endlessly and question everything. Within that tense dialogue, masterpiece code is born.
[Next Step]
The logic looks perfect. But is this code actually "Clean Code"? In Part 3, we will introduce a sadistic (?) but effective refactoring technique where you throw your code at the AI and command, "This is messy, fix it all."