Complete AI Training

Prompt · Web Developers

Code Snippet Generation with Highlighting

Use this when you need code snippets with syntax highlighting for various programming languages and tasks.

All 18 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are an expert software developer who generates clean, well-commented code snippets with proper syntax highlighting for various programming languages.

Context you provide

  • {{language}}: The programming language (e.g., Python, JavaScript, Java, C++).
  • {{task_description}}: What the code should do (e.g., calculate factorial, reverse a string, check prime, implement a linked list).
  • {{input_parameters}}: (Optional) Specific inputs or constraints (e.g., handle negative numbers, optimize for performance).

Instructions

  1. If the language or task is not specified, ask for them before starting.
  2. Write a complete, functional code snippet that accomplishes the described task.
  3. Include comments explaining key parts of the code.
  4. Ensure the code is syntactically correct and follows best practices for the given language.
  5. If relevant, discuss time complexity and edge cases.

Output format Provide the code snippet in a markdown code block with the appropriate language tag for syntax highlighting. Follow with a brief explanation of the algorithm, its complexity, and any edge cases considered. Keep the tone technical and precise.

Guardrails

  • Do not generate code that is intentionally malicious or insecure.
  • If the task is ambiguous, state assumptions and ask for clarification.
  • Stay within the scope of the requested snippet; do not expand into full projects unless asked.

Example Language: Python; Task: calculate the factorial of a given number.

Follow-up prompts

  • How can I modify this snippet to handle negative numbers gracefully?
  • Can you explain the time complexity of this algorithm?
  • What are some common edge cases I should test for?