Skip to main content

Insight of the Day! detail and precise guide (emphasizement in many example) in making prompt that is easy and friendly to be understood by AI Coding Assistant +STEERING the AI

 Of course! Here is a detailed, precise, and example-rich guide to crafting prompts that AI Coding Assistants (like GitHub Copilot, Claude, Cursor, ChatGPT for code) will understand and execute effectively.


The Core Philosophy: "Talk to the AI Like a Junior Developer"


Imagine a brilliant junior developer. They are fast and know a lot, but they lack context, make assumptions, and can't read your mind. Your goal is to provide clarity, context, and constraints.


---


The 4 Pillars of an Effective Coding Prompt


1. Context: What is the environment? (File, framework, language)

2. Task: What do you want to achieve? (Create, fix, modify, explain)

3. Requirements & Constraints: How should it be done? (Specifics, rules, edge cases)

4. Format & Output: What should the final result look like? (Code, list, comment-only)


---


Pillar 1: Context - Set the Stage


The AI doesn't know what file you're in or what project you're working on unless you tell it.


How to provide context:


· Start a comment with the language/framework.

· Mention the file you are in.

· If relevant, reference other parts of your codebase.


Bad Example (No Context):


```python

# Make a function to fetch users.

```


Why it's bad: The AI has to guess everything. From a database? An API? What's the return type?


Good Examples (With Context):


```python

# In a Django model file (models.py), create a function to fetch active users from the database.

```


```javascript

// In this React component (UserProfile.js), using the existing 'api' library, write a function to update the user's email.

```


```python

# File: utils/email_sender.py

# We have an SMTP server configured at `smtp_server`. Write a function to send a welcome email.

```


Why it's good: The AI now knows the language, framework, environment, and even existing variables to use.


---


Pillar 2: Task - Be Specific and Action-Oriented


Use clear, imperative verbs. "Create", "Write", "Fix", "Refactor", "Translate", "Explain".


Bad Example (Vague Task):


```python

# Do something with this list.

```


Why it's bad: "Do something" is meaningless. Sort it? Filter it? Print it? Send it to the moon?


Good Examples (Specific Task):


```python

# Write a function called `filter_even_numbers` that takes a list of integers and returns a new list containing only the even numbers.

```


```javascript

// Refactor this `fetch` call into an async/await function named `getPostData`.

```


```python

# Fix the bug in this function. It's supposed to calculate the factorial, but it returns 0 for any input above 1.

def factorial(n):

    if n == 0:

        return 1

    else:

        return n * factorial(n-1)

```


Why it's good: The AI knows the exact action, the intended outcome, and in the last case, has the broken code to analyze.


---


Pillar 3: Requirements & Constraints - The Devil is in the Details


This is the most crucial part for getting precise results. List your specifications.


Types of Constraints:


· Input/Output: Parameter types, return types.

· Behavioral: How it should handle errors, specific algorithms to use, performance considerations.

· Stylistic: Naming conventions, code style (e.g., "use a lambda function").

· Libraries: Specific libraries or functions to use or avoid.


Bad Example (No Constraints):


```python

# Connect to a database.

```


Why it's bad: Which database? PostgreSQL? SQLite? What are the credentials? Using SQLAlchemy or psycopg2?


Good Examples (With Detailed Constraints):


```python

# Write a Python function `safe_divide(a: float, b: float) -> float`.

# Requirements:

# 1. It should return the result of a / b.

# 2. If b is zero, return 0.0 instead of throwing an error.

# 3. Use type hints as shown.

```


```javascript

// Create a React hook `useLocalStorage` for synchronizing state with localStorage.

// Requirements:

// 1. It should take a key (string) and an initial value.

// 2. It returns an array [value, setValue], just like useState.

// 3. On mount, it reads from localStorage. If the key doesn't exist, use the initial value.

// 4. When the value is set via setValue, it should also update localStorage.

```


```python

# Using the `requests` library, write a function to GET data from 'https://api.example.com/data'.

# Constraints:

# 1. Add a timeout of 5 seconds.

# 2. Handle potential `requests.exceptions.Timeout` and `requests.exceptions.ConnectionError`.

# 3. On success, return the JSON response. On failure, return None.

```


Why it's good: The AI has a precise blueprint to follow. It knows about edge cases, error handling, and the exact library to use.


---


Pillar 4: Format & Output - Define the Deliverable


Tell the AI exactly what form you want the answer in.


Common Output Types:


· Code Block: The default. You just want the code.

· Code with Comments: "Write the code and add detailed inline comments."

· Explanation Only: "Explain what this regular expression does: /^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,}$/"

· Step-by-Step Plan: "Give me a step-by-step plan to implement OAuth in my Next.js app before writing code."


Examples:


```python

# Write a Python function to check for a prime number. Output only the code, no explanations.

```


```javascript

// Refactor this Vue.js component to use the Composition API. Please add comments to explain the new syntax compared to the Options API.

```


---


Putting It All Together: The "Perfect Prompt" Template


Combine all four pillars into a single, powerful prompt.


Template:


```

[CONTEXT] In [File/Language/Framework],

[TASK] I need to [Clear Action].

[REQUIREMENTS] The requirements are:

- Requirement 1...

- Requirement 2...

- Constraint 1...

[OUTPUT FORMAT] Please provide [Desired Output Format].

```


Real-World Example Using the Template:


Context: In my Flask application (app.py),

Task: I need to create a new API endpoint at /api/users/<id>.

Requirements:


· It should handle a GET request.

· It fetches the user from the SQLAlchemy User model by the provided id.

· If the user is found, return a JSON object with { "id", "username", "email" } and a 200 status.

· If the user is not found, return a JSON { "error": "User not found" } with a 404 status.

  Output Format: Write the complete Python function with the route decorator.


This prompt will almost certainly generate a perfect, production-ready Flask route.


Advanced Techniques & Pro-Tips


1. Iterative Prompting: Don't try to do everything in one go.

   · Prompt 1: "Give me a plan to set up a Node.js server with Express and Socket.io."

   · Prompt 2: "Now, implement step 1: create the basic Express server in a file server.js."

2. Provide Examples (Few-Shot Learning): Show the AI the pattern you want.

   ```javascript

   // Example 1: A function that adds two numbers

   const add = (a, b) => a + b;

   

   // Example 2: A function that multiplies two numbers

   const multiply = (a, b) => a * b;

   

   // Now, write a function that subtracts the second number from the first.

   ```

3. Use Code Comments to "Steer" the AI: As you type code, use comments to tell the AI what should come next. This is extremely effective in IDEs with inline completion.

   ```python

   def calculate_total(cart):

       subtotal = sum(item['price'] for item in cart)

       # Now, apply a 10% tax if the subtotal is over $100, otherwise no tax.

       # Then, apply a $5 shipping fee, but waive it if the final total is over $150.

       # Finally, return the final total.

   ```

   The AI will beautifully fill in the logic based on your comment.


By following this guide, you shift from hoping the AI understands you to knowing you've given it the best possible chance to succeed. Happy prompting


STEERING AI Coding Assistant

Comments

Popular posts from this blog

[ERROR BUG]
ChatGPT+Gemini: TikTok → Blogger Embed Converter using Cloudflare/Online Server

🔄 Refresh Page ERROR BUG: The connection is blocked because it was initiated by a public page to connect to devices or servers on your local network. Planning: Revise Program CODE Code USING Javascript/Online Server Code NOT USING Javascript Sample Working Code aka Already Repaired! Temporary Solution is by Asking AI Assistant to do REPAIR CODE of (Not yet Repaired) Current Conversion Program Code-Output TikTok Archive – Embedded Preview TikTok Embed ▶ View this video on TikTok ⚠️ DISCLAIMER: INPUT URL LIMITATION This program is currently restricted to processing Full Browser URLs only. It does not support TikTok’s mobile "short-link" format (e.g., vt.tiktok.com ). Required Action: Users must open the video in a web browser and copy the expanded URL from the address bar before pasting it into this program. URL Conversion Example ❌ UNSUPPORTED: https://vt.tiktok.com/ZSaXoFyov/ ✅ REQ...

Repost! Web-Based to Android Apps Convertion (MEDIAN.CO etc.)

CONTOH HASIL Android APK "PROGRAM" SAMPLE: Youtube and Instagram EMBEDded to Blogger/Blogspot.com SOURCE CODE Click this box to download Contoh Sample SHORTCUT-APPs "precise" click to download : median.co R8: ronin1985.blogspot.com R2M: ronin-manu.blogspot.com Gw udah coba Median.co utk mengubah Website gw menjadi Aplikasi Android Keren bet!! Median.co Cekidot Software lain yg mirip! ChatGPT : If you're looking for tools similar to Median.co to convert websites into Android apps, here are some top alternatives, especially for no-code or low-code users: 🔧 Best Tools Like Median.co to Convert Website to Android Apps 1. WebViewGold Platform: Windows/macOS (Xcode/Android Studio) Key Feature: Converts any website into iOS/Android app via WebView. Pros: One-time purchase Custom splash screen, push notifications Can open external links in external browser Cons:  Requi...

REPOST: Studying WATER PUMP by ROMAN ENGINEERING

*^ Ini yg Asli Gan! Mekanisme pada Concrete Pump: Kok ky Sistem Mekanik Romawi ya?! Tapi malah bisa HANYA pake PER aka bukan "MATA BOR look a like" Mekanisme Drill yg Cost Pembuatan bikin REPOT aka harus Tool SUPER Khusus Dari Material Besi yg digunakan terlihat langsung secara kasat mata Jauh Lebih Banyak drpd Per Biasa seperti yg ditunjukkan pd Video Alternatif dgn Penggunaan PER Video dr Instagram: Source: YouTube Rome's drainage machines #history #romanempire #engineering