🏠 Home 👤 About ⚡ Skills 💼 Portfolio 📦 Packages 📝 Blog ✉ Contact ✉ Contact Now
All Articles

Prompting Patterns That Actually Work for Code Generation

The difference between AI output you throw away and AI output you ship is almost entirely in how you asked. Six patterns I use daily.

Junaid Ali 2 min read 0 views

Most complaints about AI-generated code are really complaints about under-specified requests. The model is not reading your mind about your codebase's conventions — and it should not have to guess.

1. Give the Contract, Not the Goal

"Write a function to handle bookings" produces something generic. "Write a method that takes a validated array with keys course_id, starts_at, user_id, creates a Booking, dispatches SendBookingConfirmation, and returns the Booking" produces something you can use.

2. Paste Real Code as the Style Reference

Include one existing file from your project and say "match this style". You will get matching naming, matching error handling, matching structure — instead of a different dialect in every file.

3. Constrain the Scope Explicitly

Say what not to do. "Do not add new dependencies. Do not change the database schema. Do not refactor surrounding code." Without this, you get helpful-but-unwanted changes buried in the diff.

4. Ask for the Test First

Requesting the test before the implementation forces the edge cases into the open where you can review them. If the test list looks wrong, the implementation was going to be wrong too — and you found out in ten seconds.

5. Ask for the Trade-offs

"Give me two approaches and the trade-off between them" is far more useful than one confident answer. You stay the decision-maker, which is exactly where you should be.

6. Iterate on Specifics, Not Vibes

"Make it better" gets you noise. "Extract the date validation into a private method and handle the null case explicitly" gets you the change you wanted.

The Review Step Is Not Optional

None of these patterns remove the need to read the output carefully. They just raise the starting quality enough that reading it is worth your time.

Tagged AI Prompting Productivity Development Workflow
Share this article

Want this built properly?

I take on a small number of projects at a time so each one gets real attention.

WhatsApp Teams LinkedIn Facebook GitHub