Appendix A — Prompt Templates
This appendix provides a collection of prompt templates that can be used as starting points for different programming tasks. These templates follow the intentional prompting patterns discussed in Chapter 10.
A.1 Problem Analysis Templates
A.1.1 Understanding Requirements
I need to write a program that [brief description of the problem].
To make sure I understand the requirements correctly:
1. Is the goal to [restate the problem in your own words]?
2. What inputs should the program accept?
3. What should the output format be?
4. Are there any specific constraints or edge cases I should consider?
A.1.2 Exploring Problem Complexity
I'm trying to understand the complexity of [problem description].
1. What is the theoretical time complexity of solving this problem?
2. Are there any known algorithms for this type of problem?
3. What are the trade-offs between different approaches?
A.2 Learning-Oriented Templates
A.2.1 Concept Explanation
I'm trying to understand [programming concept].
1. Can you explain this concept in simple terms?
2. What problem does this concept solve?
3. Can you show a simple example of it in use?
4. What are common mistakes or misconceptions about this concept?
A.2.2 Code Comprehension
I'm trying to understand this code:
[paste code]
1. Can you explain what this code does, line by line?
2. What is the purpose of [specific variable or function]?
3. Are there any potential issues or inefficiencies in this implementation?
A.3 Development Templates
A.3.1 Incremental Development
I'm building a [description of program].
So far, I've implemented:
[describe current functionality or paste code]
Now, I want to add [new feature]. Can you help me:
1. Design an approach for this feature
2. Integrate it with my existing code
3. Test that it works correctly
A.3.2 Refactoring
I have this working code:
[paste code]
I'd like to refactor it to improve [readability/performance/maintainability].
Specifically, I'm concerned about [specific issue].
Can you suggest a better approach while maintaining the same functionality?
A.4 Debugging Templates
A.4.1 Error Diagnosis
I'm getting this error when running my code:
[paste error message]
Here's the relevant code:
[paste code]
1. What's causing this error?
2. How can I fix it?
3. How could I have prevented this error?
A.4.2 Performance Issue
My code is running slower than expected:
[paste code]
1. Can you identify any performance bottlenecks?
2. How could I optimize this code?
3. Are there any built-in functions or libraries that would help?
A.5 Architecture Templates
A.5.1 Design Pattern Selection
I'm building a system that needs to [describe functionality].
The key requirements are:
- [requirement 1]
- [requirement 2]
- [requirement 3]
What design pattern(s) might be appropriate for this situation?
For each suggested pattern, could you explain:
1. Why it fits this case
2. How I would implement it
3. Potential drawbacks or limitations
A.5.2 Component Design
I'm designing a [component type] that will [component purpose].
It needs to interact with:
- [related component 1]
- [related component 2]
Can you help me design this component with:
1. A clear interface (methods/functions it should expose)
2. Internal data structures
3. Error handling approach
4. Testing strategy
A.6 Testing Templates
A.6.1 Test Case Generation
I've written this function:
[paste function]
Can you help me design a comprehensive set of test cases that cover:
1. Normal operation
2. Edge cases
3. Error conditions
4. Performance considerations
A.6.2 Testing Strategy
I'm building a [type of application] and need to develop a testing strategy.
The key features are:
- [feature 1]
- [feature 2]
- [feature 3]
What types of tests should I implement (unit, integration, etc.)?
For each type, what specific aspects should I focus on testing?
A.7 Using These Templates Effectively
These templates are starting points, not rigid formulas. Adapt them to your specific needs and combine different templates as appropriate. The most effective prompting often involves:
- Starting with a clear problem statement
- Providing relevant context
- Asking specific, focused questions
- Following up with refinement questions based on the AI’s response
Remember that the goal isn’t just to get a solution, but to engage in a dialogue that deepens your understanding and improves your programming skills.