DEV Community

Cover image for The Art of Talking to AI: Prompts That Actually Work for Coding
Aditya
Aditya Subscriber

Posted on

The Art of Talking to AI: Prompts That Actually Work for Coding

Why This Matters

Chatgpt

If you're new to coding, you've probably heard about AI tools like ChatGPT, GitHub Copilot, or Cursor that can help write code. Maybe you've tried them and got frustrated when they gave you confusing or broken code.

Here's the thing: AI is incredibly powerful, but it's not a mind reader. The secret isn't just asking AI to write code—it's learning how to ask the right way.

Think of it like this: If you walked up to a expert programmer and said "make me a website," they'd probably ask you dozens of questions before writing a single line of code. AI needs the same clarity.

The Golden Rule: Be Specific

The biggest mistake beginners make is being too vague. Let's see the difference:

❌ Vague Prompt (Bad)

"Create a button"
Enter fullscreen mode Exit fullscreen mode

✅ Specific Prompt (Good)

"Create a blue button with white text that says 'Submit' and changes 
to a darker blue when you hover over it. Use HTML and CSS."
Enter fullscreen mode Exit fullscreen mode

Why the second one works better:

  • Specifies the color (blue)
  • Tells what text to show ('Submit')
  • Explains the behavior (hover effect)
  • Mentions the languages to use (HTML and CSS)

The 5 Simple Rules for Better AI Prompts

Rule 1: Tell AI What You're Building

Instead of just asking for code, explain the bigger picture.

Example:

"I'm building a simple to-do list app for beginners. I need a function 
that adds a new task to an array and displays it on the webpage. 
Use JavaScript and make it easy to understand."
Enter fullscreen mode Exit fullscreen mode

Rule 2: Mention Your Skill Level

Don't be shy about being a beginner! AI can adjust its explanations.

Example:

"I'm new to JavaScript. Can you create a simple calculator that adds 
two numbers? Please explain each line of code so I can learn."
Enter fullscreen mode Exit fullscreen mode

Rule 3: Specify the Languages/Tools

AI knows hundreds of programming languages. Tell it which ones you want.

Example:

"Create a contact form using HTML for structure, CSS for styling, 
and JavaScript for validation. I'm learning web development basics."
Enter fullscreen mode Exit fullscreen mode

Rule 4: Ask for Explanations

Code without understanding is just copy-pasting. Ask AI to teach you.

Example:

"Create a simple function that checks if a password is strong enough. 
Use Python and explain what each part does so I can understand the logic."
Enter fullscreen mode Exit fullscreen mode

Rule 5: Be Clear About the Output

Tell AI exactly how you want the response formatted.

Example:

"Give me the HTML and CSS code separately, add comments to explain 
each section, and include instructions on how to test it in a browser."
Enter fullscreen mode Exit fullscreen mode

Real Examples: Before and After

Example 1: Creating a Simple Webpage

❌ Bad Prompt:

"Make a webpage"
Enter fullscreen mode Exit fullscreen mode

✅ Good Prompt:

"Create a simple personal webpage for a beginner. Include:
- A header with my name 'John Doe'
- A paragraph about me
- A list of my hobbies
- Basic CSS to make it look nice
- Comments explaining each HTML tag
Use beginner-friendly HTML and CSS only."
Enter fullscreen mode Exit fullscreen mode

Example 2: JavaScript Function

❌ Bad Prompt:

"Write a function"
Enter fullscreen mode Exit fullscreen mode

✅ Good Prompt:

"I'm learning JavaScript functions. Create a simple function that:
- Takes a person's age as input
- Returns whether they can vote (18 or older)
- Include comments explaining how if/else statements work
- Show me how to test the function with different ages"
Enter fullscreen mode Exit fullscreen mode

Example 3: Fixing Broken Code

❌ Bad Prompt:

"This doesn't work, fix it"
Enter fullscreen mode Exit fullscreen mode

✅ Good Prompt:

"I'm a beginner and this JavaScript code isn't working. Here's my code:
[paste your code]

The error message says: [paste error message]

Can you explain what's wrong and show me the fixed version? 
Please explain why the error happened so I can avoid it next time."
Enter fullscreen mode Exit fullscreen mode

Prompt Templates You Can Use Right Now

Copy these templates and fill in your specific needs:

For Learning New Concepts

"I'm learning [topic/language]. Can you create a simple example of 
[specific thing] with comments explaining each part? Make it beginner-friendly."
Enter fullscreen mode Exit fullscreen mode

For Building Projects

"I'm building a [type of project] as a beginner project. I need 
[specific feature] that does [specific action]. Use [languages] 
and include comments explaining the code."
Enter fullscreen mode Exit fullscreen mode

For Debugging Help

"I'm new to programming and have an error. Here's my code: [code]
The error is: [error message]
Can you explain what's wrong and show me how to fix it?"
Enter fullscreen mode Exit fullscreen mode

For Code Review

"I wrote this [language] code as a beginner. Can you review it and 
suggest improvements? Please explain why each suggestion would make 
the code better: [your code]"
Enter fullscreen mode Exit fullscreen mode

Common Beginner Mistakes to Avoid

Mistake 1: Assuming AI Knows Your Setup

Don't say: "The code doesn't work"
Instead say: "I'm using Chrome browser on Windows, and when I open my HTML file, the button doesn't change color when I hover over it"

Mistake 2: Asking for Everything at Once

Don't say: "Build me a complete social media app"
Instead say: "Help me create a simple user registration form first, then we can add more features later"

Mistake 3: Not Asking Follow-up Questions

If you don't understand something, ask! AI is patient and won't judge you.

Good follow-ups:

  • "Can you explain what this line does?"
  • "What does this error mean?"
  • "Is there a simpler way to do this?"

Level Up Your AI Conversations

As you get more comfortable, you can start having actual conversations with AI:

You: "Create a simple JavaScript function that calculates the area of a rectangle"

AI: [Provides code]

You: "Can you modify it to also calculate the perimeter? And explain the math behind both calculations?"

AI: [Provides updated code with explanations]

You: "What if I wanted to make this work for any shape, not just rectangles?"

This back-and-forth approach helps you learn while building exactly what you need.

Remember: Every expert was once a beginner. The difference is they learned how to ask better questions. With these prompting techniques, you're not just getting code—you're accelerating your learning journey.

Happy coding!

Anil kapoor

Top comments (34)

Collapse
 
leob profile image
leob

Great article - and I'm pretty sure it wasn't written by AI ! (interesting - can AI already think or reason about ... AI ?)

Collapse
 
juny34 profile image
Anthony Nwagbaoso Onyeador

*Great comment here. Thought so myself *

Collapse
 
extinctsion profile image
Aditya

Sorry but saying truth.... this article was formatted in english by AI. I used my own dev.to mcp server to write about the article in plain english(you can find this in my github).
Atfirst i think about good quality topic and write an outline. I feed that outline in a LLM. Then the prompt generated by AI, I feed that in my mcp server and it creates a post for dev.to. Finally I tweak some changes, add some gifs and then publish my articles live.

So, yes AI is creating content for another AI

Collapse
 
js402 profile image
Alexander Ertli

No need to apologize genAI isn’t magic...
Thanks for the article btw.

This while AI thing... It's just a force multiplier of what you already understand, and not a substitute for intuition, knowledge, or structure...
On it's own models only output meaningful content if the question/prompt you provide hits the training data.

Thread Thread
 
extinctsion profile image
Aditya • Edited

Exactly, this is how it works and provides us with meaningful outputs.

Collapse
 
leob profile image
leob

That's clever! You still "authored" it, but used "AI" as your 'editor-in-chief' (or should I say "ghost writer") :)

Thread Thread
 
extinctsion profile image
Aditya • Edited

Yes, AI is now my junior support and it helps me achieving my goals faster than ever.

Collapse
 
anik_sikder_313 profile image
Anik Sikder

AI tools like ChatGPT, GitHub Copilot, and Cursor are amazing but only if you know how to talk to them. I love how this guide breaks down the art of prompting with clear examples and real-world tips.
The “be specific” rule is gold. I’ve seen huge improvements just by adding context like skill level, language, and desired output.
This isn’t just about getting code it’s about learning smarter and faster. Bookmarking this for every new coder I meet!

Collapse
 
extinctsion profile image
Aditya

I agree. People who feeds bad prompt and expects AI to do everything speaks bad about ai. They are just missing good prompt and that all they need to boost their productivity.

Collapse
 
kaymen99 profile image
Aymen K

Great stuff! I've been coding for few years now (not a pro, but I get by 😉), and I'm always arguing with Claud (windsurf) about how the code/app should work. It definitely takes some trial & error to get the prompts just right!

Collapse
 
extinctsion profile image
Aditya

I too sometimes gets struck in the merry-go-round. Then I try to switch to some other models or rephrase what I said. Even if it does not work, then I do that work myself :)

Collapse
 
rj33 profile image
RJ

I have learned writing bots in Node.js and Python with various LLMs is that once your code becomes a larger project and especially if you make it modular you need to make sure you are specific on exact changes and it does not hurt to say "Please do not change anything else".

I have had AI make changes assuming I wanted something. They do eventually get and actually state "I am leaving everything else as is".

Collapse
 
xzel profile image
Axel Howind

Articles like this are so much needed. AI needs enough context to create good answers (just as humans).

One interesting thing I noted after using AI for quite some time is how much models have improved in context awareness when you use an AI that has access to your whole project. For example, when some time ago the AI would generate working but quite verbose code, I now get answers like "here, need to be done and I noticed you already have a Utility class X with method y that does exactly that, so I used it" and provide very concise and readable code.

Collapse
 
extinctsion profile image
Aditya

Agreed, AI is all about context, dataset, training and accuracy. It is definitely improving day by day!

Collapse
 
elfreda profile image
Elfreda

These are great!
I’ve been using ChatGOT for coding and find that running the same prompt on DeepSeek and GPT-4o gives me two solid options to start with.
It’s like getting a second opinion from another senior dev.

Collapse
 
abi_abi_5fbf3e273d0ccdbbc profile image
abi abi

Great post btw. I would like to suggest create AI context engineering post like this man...

Collapse
 
extinctsion profile image
Aditya

Thanks, what kind of posts you would like to see? I post stuffs from various fields. Let me know. Also you can follow to get more such contents.

Collapse
 
abi_abi_5fbf3e273d0ccdbbc profile image
abi abi

Sure, I already following you 🙌, I want context engineering post Aaditya

Thread Thread
 
extinctsion profile image
Aditya

Okay, I'll be posting more about prompting in the upcoming posts

Collapse
 
idha profile image
Idha

Ok, let's be specific, but who prompts "write a function" anyway?

Collapse
 
extinctsion profile image
Aditya

Lol. "I know a guy who knows a guy" writes like this

Collapse
 
varshithvhegde profile image
Varshith V Hegde

that guy would be me😂

Collapse
 
prime_1 profile image
Roshan Sharma

This was a solid read. I've observed that when I simply ask for code, the output tends to be very generic. However, when I provide context, such as what I’m building, my skill level, or the programming language I want to use, the responses become much more useful. Requesting explanations alongside the code also aids my learning, as it prevents me from just copy-pasting without understanding.

Collapse
 
extinctsion profile image
Aditya

Being a good prompt engineer requires you to be a good engineer first. Your algorithm and problem solving skills decides how you gonna direct the AI to do things. That's how it always should be.

Collapse
 
smart2go profile image
Smart2GoTraining

Very good article! I been the bad and I'm getting better at prompting. The key takeaway for me is about 'specificity' - the more specific the better the results. I can't tell you how many times my coding agent and I went round and round to resolve a problem not because it was incapable, but because I was incapable of specifying what I needed. Burned through a lot of tokens on that lesson. But, here I am, 4 full-stacked apps later, fully AI generated, [I couldn't code a single line of anything!] and still can't get enough about learning how to prompt with AI.

Collapse
 
extinctsion profile image
Aditya

Im glad that you liked this article. I'm also learning on how we can use AI to leverage our productivity. Right now I'm also experimenting with prompts and its output. I'll keep writing more n more as I keep learning. I'm really happy that you liked my article!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.