Ivan Revzin

Tools to Measure Lines of Code

I deleted 132 lines of code in my first commit for my recent client. Why? Because code is a liability. Reason is simple: many lines of code = many hours of developers spent. And developers are not cheap. Reducing costs = more profit.

How did I measure how much lines I removed? Obviously git diff shows the stats. But what about comments and empty lines? If you don't want to count these you might want to use a code counter.

I tried 3 code counters:

project lang stars notes
cloc perl 15k most popular
scc go 4k gives $ estimates
tokei rust 8k blazingly fast

I ran all 3 of them on React source code (at 71cace4):

cloc

$ cloc . --not-match-d='__tests__'
      54 text files.
      53 unique files.
       2 files ignored.

github.com/AlDanial/cloc v 1.92  T=0.02 s (2145.5 files/s, 207707.3 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JavaScript                      46            408           1088           3449
JSON                             1              0              0             48
TypeScript                       5             11             60             30
Markdown                         1             11              0             26
-------------------------------------------------------------------------------
SUM:                            53            430           1148           3553
-------------------------------------------------------------------------------

scc

There's a talk by the author explaining how scc was made. Also, according to scc React took $100k to develop, lol.

$ scc --exclude-dir '__tests__'
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
JavaScript                  46      4945      408      1088     3449        530
JSON                         1        48        0         0       48          0
Markdown                     1        37       11         0       26          0
───────────────────────────────────────────────────────────────────────────────
Total                       48      5030      419      1088     3523        530
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $101,356
Estimated Schedule Effort (organic) 5.762865 months
Estimated People Required (organic) 1.562540
───────────────────────────────────────────────────────────────────────────────
Processed 150566 bytes, 0.151 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────

tokei

$ tokei --exclude '__tests__'
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 JavaScript             46         4945         3449         1088          408
 JSON                    1           48           48            0            0
 Markdown                1           37            0           26           11
===============================================================================
 Total                  48         5030         3497         1114          419
===============================================================================

Which should you chose?

They all do the same thing. Just pick the one with the documentation you like the most.

PS: don't measure developer productivity by LoC shipped

Many people already said that that measuring developer productivity by lines of code they ship is counterproductive: