54 lines
1.5 KiB
Markdown
54 lines
1.5 KiB
Markdown
# Prompting Patterns
|
|
|
|
You are here: [AI Docs Home](../index.md) > [Cross-Platform AI Usage](cross-platform.md) > Prompting Patterns
|
|
|
|
## Contents
|
|
- Why Prompt Patterns Matter
|
|
- Prompt Template
|
|
- Common Prompt Patterns
|
|
- Next Steps
|
|
|
|
## Why Prompt Patterns Matter
|
|
Good prompt patterns reduce rework. They tell the assistant exactly what to change, what not to change, and what output you expect.
|
|
|
|
## Prompt Template
|
|
Use this structure for most requests:
|
|
1. Goal: The specific outcome you want.
|
|
2. Scope: The file or function to change.
|
|
3. Constraints: What must stay the same.
|
|
4. Output: What you want returned (code only, bullets, tests, and so on).
|
|
|
|
Example prompt:
|
|
```text
|
|
Goal: Refactor validation logic for readability.
|
|
Scope: Only ValidationService.swift.
|
|
Constraints: Keep behavior and public API unchanged.
|
|
Output: Return code changes and a short list of tests to update.
|
|
```
|
|
|
|
## Common Prompt Patterns
|
|
- Refactor safely:
|
|
Example prompt:
|
|
```text
|
|
Refactor this file to improve readability without changing behavior.
|
|
```
|
|
- Add tests:
|
|
Example prompt:
|
|
```text
|
|
Add unit tests for this service. Keep the existing public API.
|
|
```
|
|
- Debug:
|
|
Example prompt:
|
|
```text
|
|
Explain this error and list likely fixes in priority order.
|
|
```
|
|
- Understand code:
|
|
Example prompt:
|
|
```text
|
|
Summarize what this module does and call out the top 3 risks.
|
|
```
|
|
|
|
## Next Steps
|
|
- Read [Prompting Anti-Patterns](prompting-antipatterns.md) to avoid common mistakes.
|
|
- Use [Starter Prompts](starter-prompts.md) when you need copy/paste examples.
|