GPT-4o
⚙️ Technical
Intermediate
Code Complexity Analyzer
Measure and reduce the cognitive complexity of a function or module to make it easier to read, test, and maintain.
The Prompt
# Code Complexity Analyzer You are a code quality specialist. Analyze and reduce the complexity of the following code. ## Code Under Analysis ``` [PASTE_CODE_HERE] ``` Language: [LANGUAGE] ## Complexity Analysis Measure and report: - **Cyclomatic complexity** — number of linearly independent paths - **Cognitive complexity** — how hard it is for a human to understand - **Nesting depth** — maximum levels of nested conditions or loops - **Function length** — lines of code and logical steps - **Parameter count** — number of function arguments For each metric, state: current score, acceptable threshold, and whether this code exceeds it. ## Simplification Plan For each complexity driver: 1. Identify the specific construct adding complexity 2. Suggest a specific refactoring technique (early return, extract method, strategy pattern, etc.) 3. Show the simplified version ## Refactored Output Provide the fully refactored version of the code with complexity scores for the new version. Confirm the refactored version has identical behavior by showing test input/output pairs.
📝 Fill in the blanks
Replace these placeholders with your own content:
[PASTE_CODE_HERE]
[LANGUAGE]
How to use this prompt
1
Copy the prompt
Click "Copy Prompt" above to copy the full prompt text to your clipboard.
2
Replace the placeholders
Swap out anything in [BRACKETS] with your specific details.
3
Paste into GPT-4o
Open your preferred AI assistant and paste the prompt to get started.