
Practical guide to developer-prompted engineering in the era of generative AI
- Development
- 31 May, 2024
Introduction: Why do developers need prompt engineering?
In an era where generative AI writes code and fixes bugs, the role of developers is rapidly evolving from simply ‘typing’ code to ‘designing and solving’ problems by collaborating with AI. The most important competency here is Prompt Engineering. Prompt engineering is a technology that optimizes and designs instructions (prompts) so that the AI model can produce the best results.
Even if the same AI model is used, the quality and accuracy of the generated code varies greatly depending on how the prompt is written. If you roughly type “Create a membership sign-up function,” you will get obvious and weak code, but if you give specific conditions and context, you can get solid code that can be immediately applied to actual work. In this article, we introduce practical prompt writing techniques for developers to fully utilize generative AI (ChatGPT, Claude, etc.) in practice.
4 Key Elements of a Good Prompt (CRISPE Framework)
When writing prompts, you will get much better results if you take a structured approach rather than asking questions blindly. Let's apply CRISPE, one of the most popular prompt writing frameworks, to a development context.
- Capacity and Role: Give AI a role as an expert.
- Example: “You are a 10-year senior React front-end developer and web accessibility expert.”
- Insight (background knowledge/context): Describes the current project situation or background of the problem being solved.
- Example: "I'm currently developing an e-commerce site using Next.js 14 (App Router) and Tailwind CSS."
- Statement (clear instructions): Requests specifically what to do.
- Example: “Design a shopping cart component and implement state management using Zustand.”
- Personality (Style/Tone): Specifies the format or style of the answer.
- Example: "Keep the explanation concise and provide sufficient comments in the code. Strictly apply TypeScript typing."
- Experiment (Output Format): Specifies the format of the output.
- Example: "Write the code in Markdown blocks, and also provide the necessary npm installation commands."
Practical prompt patterns for developers
1. Zero-Shot Prompting vs Few-Shot Prompting
- Zero-Shot Prompting: This is a method of giving instructions right away without examples. Perfect for simple conceptual questions or generating boilerplate code.
- Few-Shot Prompting: This is a method of letting AI learn patterns by providing several examples (input-output pairs) of the desired output. It is very effective when following specific coding conventions or directing complex data transformation tasks.
[Few-Shot Prompt Example] Refer to the following example to create a function that converts a Python dictionary into a JSON string in the given format.
Example 1: Input:
{'name': 'Alice', 'age': 30}Output:{"user_name": "Alice", "user_age": 30}Example 2: Input:
{'name': 'Bob', 'age': 25}Output:{"user_name": "Bob", "user_age": 25}Actual task:
{'name': 'Charlie', 'age': 40, 'city': 'Seoul'}
2. Request code review and refactoring
AI does a very good job as a code reviewer. Rather than just pasting in code and saying, "Please review this," it's a good idea to specify a point to focus on.
[Refactoring prompt example] The following Python code is too long and complex to maintain.
- Apply the Clean Code principle to improve readability.
- Separate overlapping logic into separate functions.
- If there is a way to optimize the time complexity to O(n), apply it. [insert code here]
3. Bug debugging and error resolution
Rather than just providing an error message, you can receive a much more accurate cause analysis if you provide the situation where the error occurred, related code, and attempted solutions.
[Example debugging prompt] I was loading API data using the useEffect hook in React, but I ran into an infinite loop. Environment: React 18, axios Error details: Browser stopped due to memory overload. There are no special console errors. Code I wrote: [insert code here] Please explain why the infinite loop occurs and suggest corrected code.
4. Automatic generation of test code
Writing test code is an important but cumbersome task. Using AI, this time can be significantly reduced.
[Example test code prompt] Below is a TypeScript utility function that checks email validity. Please write the Jest unit test code for this function. Requirements:
- Cover success and failure cases (including edge cases) thoroughly.
- Structure it in BDD style (describe, it). [Insert function code here]
Tips to keep in mind when writing prompts
- Specify restrictions: Make restrictions clear, such as “Do not use external libraries and write only pure vanilla JS,” “Use ES6+ syntax,” etc. to prevent the code from developing in an undesirable direction.
- Chain of Thought: When designing a complex architecture or algorithm, don't ask for everything at once. If you take a step-by-step approach such as “First design the database schema” -> “Then organize the related API endpoints” -> “Finally write the controller code”, the quality of the result will be much higher.
- Beware of hallucinations: AI-generated code is not always perfect. You may be using a non-existent library or have grammatical errors. You must carefully review the generated code and test it yourself. We must keep in mind that AI is only an ‘assistant’ and the person responsible is the ‘developer’ himself.
- Inducing a reverse question: Adding the question to the AI at the end of the prompt, “Are my requirements clear enough? Please ask me a question if you need additional information before starting coding,” is very useful as it allows you to identify exception cases or constraints that may have been missed in advance.
Conclusion: Prompts are the new ‘language’ of developers
In the past, being good at programming languages such as C, Java, and Python was a core competency, but now 'Prompt', which efficiently controls AI with natural language, has become a new essential development language. Prompt Engineering skills are not developed overnight. Every day at work, we need to repeatedly talk to AI and experiment and record which instructions lead to better code. I hope you will immediately apply the tips you learned today in practice and become a smart developer leading the AI era.












