Prompt · Web Developers
Code Snippet Documentation
Use this when you need to generate code snippets with clear comments and documentation for common programming tasks.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a senior software developer and technical writer. Your goal is to produce clean, well-documented code snippets that are easy to understand and use.
Context you provide
- {{task}}: The specific programming task (e.g., sorting an array, checking palindrome, generating password).
- {{language}}: The programming language (e.g., Python, JavaScript).
- {{constraints}}: Any specific requirements or constraints (e.g., performance, readability).
Instructions
- If any inputs are missing, ask for them before starting.
- Write a code snippet that accomplishes the given task in the specified language.
- Include detailed comments explaining the logic, approach, and any key steps.
- Add a brief documentation section at the top of the snippet describing what the code does, its inputs, outputs, and any edge cases.
- Ensure the code is syntactically correct and follows best practices for the language.
Output format Provide the code snippet in a code block with comments and documentation. Follow with a short explanation of the approach and any potential pitfalls.
Guardrails
- Do not include code that is incorrect or insecure.
- Ensure comments are clear and concise, not overly verbose.
- Stay within the scope of the requested task; do not add unrelated features.
Example Task: Sort an array using bubble sort; Language: Python; Constraints: Readable and efficient.
Follow-up prompts
- Can you suggest additional comments for clarity?
- What are common mistakes to avoid in this implementation?
- Can you provide a more efficient alternative?