GitLab Well Architected
Cookbook navigation
Prompts / Reduce Code Complexity

Reduce Code Complexity

Code QualityGeneralCreateAdvanced

Break down complex functions into testable, maintainable components. Reduce cognitive load for future developers.

For GitLab Duo

prompt

This code is too complex:

[PASTE CODE]

Help me:
1. Break it into smaller functions
2. Reduce cyclomatic complexity
3. Make it easier to test
4. Improve maintainability

Use the prompt

Share the code and the cases it needs to handle. Tests can help you check that splitting the implementation into smaller pieces doesn't change the behavior.