Code Complexity Visualizer
Analyze and visualize complexity metrics for Go source code
Analysis Mode:
Browser (WASM)
Server
Analyze
Try Sample Data
Sample Code
SimpleFunction
ComplexFunction
Cyclomatic Complexity
Cognitive Complexity
Maintainability Index
Lines of Code
Halstead Volume
Halstead Difficulty
Nested Depth
Comment Density
Function Parameters
Understanding Code Complexity Metrics
Core Complexity Metrics
Cyclomatic Complexity
Measures the number of linearly independent paths through code. Lower is better.
1-10: Simple, well-structured code
11-20: Moderately complex
21+: Complex code that might need refactoring
Cognitive Complexity
Measures how difficult the code is to understand. Lower is better.
0-5: Easy to understand
6-15: Moderately difficult
16+: Complex, consider breaking down
Maintainability Index
A composite metric indicating code maintainability (0-100).
85-100: Highly maintainable
65-84: Moderately maintainable
0-64: Difficult to maintain
Halstead Metrics
Volume
Represents the size of the implementation. Affected by:
Number of operators (if, for, etc.)
Number of operands (variables, constants)
Program length
Difficulty
Indicates how hard the code is to write or understand. Influenced by:
Unique operators
Total operands
Program complexity
Additional Metrics
Nested Depth
Maximum level of nested control structures. Lower is better.
1-3: Good
4-5: Consider refactoring
6+: Should be refactored
Comment Density
Ratio of comments to code lines. Higher isn't always better.
0.1-0.2: Might need more documentation
0.2-0.4: Generally good
0.4+: Might be over-documented
Function Parameters
Number of parameters in the function. Fewer is usually better.
0-3: Ideal
4-5: Consider refactoring
6+: Should be refactored
Using This Tool
Browser Analysis (WASM)
Analyzes code directly in your browser
No server communication needed
Best for quick analysis of smaller files
Works offline once loaded
Server Analysis
Handles larger files more efficiently
More consistent performance
Requires server connection
Better for batch processing
Recommendations for Clean Code
Keep functions small and focused
Limit nesting depth to 3-4 levels
Keep cyclomatic complexity under 10
Maintain good comment ratio without over-documenting
Use descriptive names to reduce cognitive load
Star