openai / baselines
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 842 units with 9,429 lines of code in units (57.6% of code).
    • 9 very long units (1,372 lines of code)
    • 17 long units (1,100 lines of code)
    • 82 medium size units (2,496 lines of code)
    • 133 small units (1,944 lines of code)
    • 601 very small units (2,517 lines of code)
14% | 11% | 26% | 20% | 26%
Legend:
101+
51-100
21-50
11-20
1-10
Unit Size per Extension
101+
51-100
21-50
11-20
1-10
py14% | 11% | 26% | 20% | 26%
Unit Size per Logical Component
primary logical decomposition
101+
51-100
21-50
11-20
1-10
baselines14% | 11% | 26% | 20% | 26%
Alternative Visuals
Longest Units
Top 50 longest units
Unit# linesMcCabe index# params
232 44 19
206 51 28
200 34 28
137 35 25
133 29 25
130 42 3
113 2 19
111 31 3
110 15 19
96 44 3
74 9 5
73 29 3
73 10 5
69 13 2
67 7 16
67 12 2
64 15 1
61 8 6
61 10 2
58 8 11
58 24 4
58 10 14
56 7 7
56 3 16
56 15 4
53 8 5
50 12 1
48 7 11
47 14 12
46 4 1
44 10 6
44 5 0
43 8 4
43 6 6
43 11 5
42 12 3
41 8 4
41 9 1
40 7 1
39 3 20
39 2 5
38 9 1
38 8 1
37 10 32
36 9 5
36 17 12
35 3 4
35 13 1
34 9 12
32 6 11