openai / codex
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 13,193 units with 208,976 lines of code in units (37.8% of code).
    • 88 very long units (14,302 lines of code)
    • 440 long units (28,955 lines of code)
    • 2,504 medium size units (75,606 lines of code)
    • 3,475 small units (51,597 lines of code)
    • 6,686 very small units (38,516 lines of code)
6% | 13% | 36% | 24% | 18%
Legend:
101+
51-100
21-50
11-20
1-10
Unit Size per Extension
101+
51-100
21-50
11-20
1-10
rs6% | 13% | 36% | 24% | 18%
py8% | 11% | 28% | 24% | 28%
ts0% | 22% | 29% | 26% | 21%
js0% | 0% | 0% | 100% | 0%
Unit Size per Logical Component
primary logical decomposition
101+
51-100
21-50
11-20
1-10
codex-rs6% | 13% | 36% | 24% | 18%
.codex9% | 8% | 38% | 26% | 16%
scripts8% | 16% | 23% | 21% | 31%
sdk0% | 11% | 24% | 29% | 34%
codex-cli0% | 56% | 29% | 5% | 7%
tools0% | 16% | 19% | 23% | 40%
.github0% | 7% | 35% | 22% | 35%
bazel0% | 0% | 51% | 29% | 18%
.devcontainer0% | 0% | 63% | 0% | 36%
Alternative Visuals
Longest Units
Top 50 longest units
Unit# linesMcCabe index# params
507 8 1
426 60 1
411 1 0
324 2 2
316 28 0
316 1 1
299 45 4
296 14 1
270 1 0
255 1 0
253 15 4
245 1 0
245 29 3
230 46 2
223 41 2
222 26 3
206 20 3
205 25 4
203 21 2
201 44 0
193 4 0
185 30 0
176 2 2
174 1 0
171 4 0
170 22 6
167 10 3
153 21 3
148 2 0
148 23 2
145 11 5
143 1 0
142 29 2
142 12 4
142 1 2
141 23 1
141 8 2
137 30 1
135 1 0
135 17 1
134 15 3
133 52 2
130 13 3
130 17 2
129 3 0
128 2 5
127 18 2
126 9 4
125 6 3
124 7 1