Function Length Inspector
Description & Learning Section
Keeping functions small and focused improves readability, testability, and maintainability. Large functions often violate the “single responsibility” principle and become hard to debug.
Metrics Explained:
- Total Lines: Every line from definition to end, including blank and comment lines.
- Code Lines: Non‑blank, non‑comment lines—your actual executable code.
- Comment Lines: Lines starting with
#,//, or/*. - Blank Lines: For readability separation, not counted as code.
Threshold & Sorting:
- Flag functions exceeding your code or total‑line threshold.
- Sort the list by either metric to quickly find the largest offenders.
Statistics & Histograms:
- See min/max/average/median for both total and code lines.
- Visualize distribution with a simple “*”‑based histogram (1 * per 5 lines).
Example:
def example(a, b):
# Initialize
result = a + b
if result > 10:
# deep logic
for i in range(result):
print(i)
else:
print("small")
return result
- Total Lines: 10
- Code Lines: 6 (every executable statement)
- Comment Lines: 2
- Blank Lines: 2
Use this enhanced **Function Length Inspector** to enforce concise functions, track code growth, and guide refactoring efforts.