openai / kubernetes
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 43,398 units with 503,708 lines of code in units (69.0% of code).
    • 241 very long units (46,488 lines of code)
    • 849 long units (56,418 lines of code)
    • 4,713 medium size units (142,879 lines of code)
    • 7,623 small units (110,792 lines of code)
    • 29,972 very small units (147,131 lines of code)
9% | 11% | 28% | 21% | 29%
Legend:
101+
51-100
21-50
11-20
1-10
Unit Size per Extension
101+
51-100
21-50
11-20
1-10
go9% | 11% | 28% | 21% | 29%
py0% | 0% | 58% | 14% | 27%
c0% | 0% | 54% | 35% | 9%
Unit Size per Logical Component
primary logical decomposition
101+
51-100
21-50
11-20
1-10
staging9% | 9% | 25% | 20% | 34%
pkg9% | 12% | 31% | 23% | 23%
cmd8% | 18% | 31% | 23% | 17%
plugin11% | 8% | 38% | 22% | 18%
hack0% | 8% | 48% | 29% | 13%
cluster0% | 0% | 58% | 31% | 9%
build0% | 0% | 69% | 23% | 6%
Alternative Visuals
Longest Units
Top 50 longest units
Unit# linesMcCabe index# params
5258 20 8
1687 842 1
718 132 1
595 65 26
577 1 1
545 95 1
514 89 1
480 107 1
464 94 1
450 12 0
407 1 1
393 66 1
359 105 1
328 1 2
309 129 2
305 66 4
304 10 0
280 83 5
273 135 1
267 65 4
264 1 0
256 69 5
250 59 1
243 95 5
242 113 6
241 82 1
235 29 1
235 46 1
232 55 1
228 44 1
228 58 2
226 56 1
225 14 1
221 51 1
218 45 1
218 52 1
217 52 1
207 73 1
205 49 1
203 44 1
197 41 1
196 44 1
193 59 1
193 36 1
191 52 0
191 39 1
190 35 1
187 49 4
187 63 1
187 21 1