4 ms·
I just calculated the 90th quantile of line length over the TXR project, for all the C, Lisp, Lex and Yacc sources: 1> (let ((q (quantile 0.9))) (each
by kazinator 5y ago
I just calculated the 90th quantile of line length over the TXR project, for all the C, Lisp, Lex and Yacc sources:
1> (let ((q (quantile 0.9)))
(each ((l (flow "git ls-files '*.c' '*.h' '*.tl' '*.y' '*.l'"
command-get-lines
open-files
get-lines)))
[q (len l)])
[q])
63.9840684046716
The project follows two character indentation except in one inherited source file and its header.
The 99th percentile:
2> (let ((q (quantile 0.99)))
[ .. SNIP ]
[q])
78.9882857548558
Of course, that's skewed by the internal pressure to stay within 80 columns.
When we go to the 99.99th percentile, things take a bit of a leap:
3> (let ((q (quantile 0.9999)))
[ .. SNIP ]
[q])
[q])
104.790549931036
Still, that shows us that long lines are quite rare. Probably the column limit set by the 99th percentile is reasonable from this perspective.
Moreover, if we want to be quite generous, we don't have to add too many columns. 105 characters will only break 1 in 10,000 lines. Something can almost certainly be done about those. Or these outliers have something wrong, like being accidentally joined or something.
--
Let's tidy up the code, by eliminating the each iteration with mapdo:
1> (let ((q (quantile 0.9999)))
(flow "git ls-files '*.c' '*.h' '*.tl' '*.y' '*.l'"
command-get-lines
open-files
get-lines
(mapdo (opip len q)))
[q])
104.790549931036
- zamadatix 5y agoAs you note towards the middle I think you're just measuring that code styles traditionally limit to 80 columns not that 80 columns was really the natural 99th percentile of freeform code lines. Similarly I don't think that shows 104+ character lines are really 1 in 10,000 it shows 1 in 10,000 lines weren't yet refactored to fit into the 80 columns per line standard. I'm all for >80 column wide lines I just don't think these stats really tell us anything about it other than 80 column lines have been the standard in the past.
- powersnail 5y agoDoes this account for blank lines?
- kazinator 5y agoNo; we can introduce a (remqual "") element or similar to the (flow ...) pipeline after get-lines to achieve that. The numbers become: 66.06, 79.61, 105.89. Different, but not by much.
- necovek 5y agoI was going to ask if someone did an analysis of the sort! Kudos! It'd be great to get a distribution graph as well, even if we can't know how long would the lines have been without a line length limit. My gut feel before reading your comment was that: * I like short limit because majority of the lines _are_ short * Shorter line length limit allows me to have more windows side-by-side-by-side, without wasting whitespace on the right side * I am willing to accept occasional awkward line break to achieve the above The question I had in my mind was how "occasional" was it, so thanks for answering that to a large extent. We could also do a deeper analysis to re-format all lines not to use line-breaks before running the numbers too. Basically, if 64 was the natural limit for 90% of the lines (sure, some are this short because of the 80-character limit), then a 20% buffer should be good enough.