anthropics / buffa
Unit Size

The distribution of size of units (measured in lines of code).

Intro
  • Unit size measurements show the distribution of size of units of code (methods, functions...).
  • Units are classified in four categories based on their size (lines of code): 1-20 (small units), 20-50 (medium size units), 51-100 (long units), 101+ (very long units).
  • You should aim at keeping units small (< 20 lines). Long units may become "bloaters", code that have increased to such gargantuan proportions that they are hard to work with.
Learn more...
  • To learn more about unit size, the Sokrates recommends the following resources:
    • Function Length, MartinFowler.com
      • "If you have to spend effort into looking at a fragment of code to figure out what it's doing, then you should extract it into a function and name the function after that 'what'."
    • Stack Overflow Discussion on Unit Size, stackoverflow.com
      • "Use common sense, stick to small function sizes in most instances but don't be dogmatic about it if you have a genuinely good reason to make an unusually big function."
    • Coding Smells, codinghorror.com
      • "All other things being equal, a shorter method is easier to read, easier to understand, and easier to troubleshoot. Refactor long methods into smaller methods if you can."
    • Clean Code: A Handbook of Agile Software Craftsmanship, by Robert Martin
      • "The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that. Functions should not be 100 lines long. Functions should hardly ever be 20 lines long."
Unit Size Overall
  • There are 2,348 units with 30,555 lines of code in units (54.4% of code).
    • 24 very long units (3,909 lines of code)
    • 62 long units (4,366 lines of code)
    • 217 medium size units (6,549 lines of code)
    • 476 small units (6,832 lines of code)
    • 1,569 very small units (8,899 lines of code)
12% | 14% | 21% | 22% | 29%
Legend:
101+
51-100
21-50
11-20
1-10
Unit Size per Extension
101+
51-100
21-50
11-20
1-10
rs12% | 13% | 21% | 22% | 29%
py22% | 28% | 17% | 18% | 12%
Unit Size per Logical Component
primary logical decomposition
101+
51-100
21-50
11-20
1-10
buffa-codegen26% | 22% | 21% | 14% | 14%
buffa-test72% | 0% | 0% | 0% | 27%
benchmarks18% | 16% | 25% | 21% | 18%
buffa1% | 6% | 17% | 28% | 46%
conformance13% | 19% | 20% | 27% | 18%
buffa-descriptor0% | 18% | 37% | 24% | 19%
buffa-types0% | 5% | 11% | 29% | 52%
protoc-gen-buffa0% | 26% | 20% | 3% | 50%
stress0% | 91% | 0% | 0% | 8%
fuzz0% | 0% | 100% | 0% | 0%
buffa-yaml0% | 0% | 22% | 40% | 37%
protoc-gen-buffa-packaging0% | 0% | 67% | 17% | 15%
buffa-build0% | 0% | 16% | 52% | 30%
scripts0% | 0% | 0% | 100% | 0%
buffa-smolstr0% | 0% | 0% | 0% | 100%
Alternative Visuals
Longest Units
Top 50 longest units
Unit# linesMcCabe index# params
573 55 4
414 1 0
183 18 1
171 15 4
166 30 4
165 17 6
163 20 6
155 12 6
136 14 3
136 27 6
133 6 11
127 12 7
127 10 6
126 3 5
124 15 5
120 12 3
120 11 4
116 12 4
112 17 4
110 17 4
109 41 1
109 7 5
108 15 5
106 13 5
98 38 2
97 5 9
96 13 5
94 3 7
92 4 0
92 14 2
92 9 1
92 12 8
91 13 3
89 16 5
88 11 3
87 4 8
86 8 4
84 24 7
83 13 3
83 7 10
80 11 2
80 31 0
75 10 11
74 4 3
74 8 5
73 10 1
73 7 3
72 2 6
72 11 4
72 10 5