Code Generation
Specifies inputs, outputs, complexity, and documentation requirements upfront. Both ChatGPT and Gemini handle this structured code spec well, producing near-identical quality output.
Write a {{language}} function that {{function_description}}. Requirements: - Input: {{input_description}} - Output: {{output_description}} - Handle edge cases: empty input, null values, invalid types - Time complexity should be O({{complexity}}) or better - Include JSDoc/docstring with parameter descriptions and return type After the function, provide: 1. Three test cases covering normal, edge, and error scenarios 2. A brief explanation of your algorithmic approach 3. One alternative approach with its tradeoff Do not include unnecessary comments in the code itself — the code should be self-documenting.
Variables to customize
Why this prompt works
Specifies inputs, outputs, complexity, and documentation requirements upfront. Both ChatGPT and Gemini handle this structured code spec well, producing near-identical quality output.
Save this prompt to your library
Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.
Related prompts
Get thorough code reviews with actionable feedback tailored to your language, framework, and standards.
Context-Aware Code CompletionProviding the surrounding code and project context lets the model match existing patterns exactly. The constraint against modifying existing code prevents unwanted side effects.
Inline Code SuggestionConstraining suggestions to match existing style and scope produces insertions that feel native to the codebase. The 'no explanation' rule mimics real inline completion behavior.
Code ExplanationThe audience level parameter adjusts complexity automatically. Requiring a usage example ensures the explanation is practical, not just theoretical.