Checking a claim
By the end of this chapter you can take a sentence like "this project is twenty thousand lines of code" and find out what, if anything, it is worth — using the lab's small rigged tree first, then a procedure that scales to a real one.
The rigged tree
fixtures/claim holds three
Python files, built to be
misquoted:
real.py— a small working file: 7 lines.padded.py— two lines of code wearing a nine-line comment banner: 12 lines.nonewline.py— one line of code with no newline at its end.
Three honest counters give three different answers:
$ wc -l tokei-lab/fixtures/claim/*.py
0 .../nonewline.py
12 .../padded.py
7 .../real.py
19 total
$ tokei --files tokei-lab/fixtures/claim
Python 3 files 20 lines 6 code 10 comments 4 blanks
Reading the disagreement
Each gap is a rule from an earlier chapter, speaking:
- 19 vs 20 lines.
wc -lcounts newline characters, andnonewline.pyhas none to count. Tokei counts the final unterminated line as a line. On any tree where files are saved by tools that skip the final newline,wcruns a little light. - 20 lines vs 6 code. Ten of the lines are comments — nine of them one banner — and four are blank. The claim "twenty lines of code" is true of the files and false of the code, and the difference is not pedantry: it is most of the number.
Neither tool lied. Each answered its own definition, which is chapter 1's rule with the gloves off.
A procedure for a real claim
- Ask which number is being claimed — lines, or code lines. If the claimant cannot say, the claim is not ready to check.
- Pin the filters before you
count. Hidden files in or out?
Ignore files respected (and is
the tree a real git repository —
chapter 8's fine print)? A
tokei.tomlin the folder you are standing in (chapter 10)? Write the choices down with the result. - Count, then look at the
receipts.
--files, sorted by size in your head: real claims die of a few giant files that turn out to be generated, vendored, or — as here — mostly banner. - Compare like with like. Two
counts argue fairly only when
the version, the flags and the
folder state match. To compare
two versions of a project, run
the identical command in both
checkouts and compare the Code
columns — the same discipline
chapter 8 used on one folder
before and after
git init.
What this procedure cannot do is make the number mean more than it does. Six honest code lines say nothing about quality, difficulty or value — chapter 13 is blunt about that. What it can do is stop a padded, mis-filtered or mislabelled count from posing as a fact.
Check: state the claim
"fixtures/claim is a 20-line
codebase" three ways — as lines
in files (true), as wc sees it
(19), and as code (6) — and say
which one you would put in a
report. If the exercise feels
easy now, you have this chapter.