Is phobos too fluffy?
Steven Schveighoffer
schveiguy at gmail.com
Sun Sep 20 15:18:47 UTC 2020
On 9/20/20 11:04 AM, Paul Backus wrote:
> On Thursday, 17 September 2020 at 15:51:18 UTC, Andrei Alexandrescu wrote:
>> As wc -l counts, phobos has some 330 KLOC:
>>
>> $ wc -l $(git ls-files '*.d') | tail -1
>> 331378 total
>>
>> I noticed many contributors are fond of inserting empty lines
>> discretionarily, sometimes even in the middle of 2-5 line functions,
>> or right after opening an "if" statement. The total number of empty
>> lines:
>>
>> $ git grep '^$' $(git ls-files '*.d') | wc -l
>> 38503
>>
>> So Phobos has 11.62% empty lines in it, on average one on every 9
>> lines of code. I find that a bit excessive, particularly given that
>> our coding convention uses brace-on-its-own line, which already adds a
>> lot of vertical space. Here's the number of lines consisting of only
>> one brace:
>>
>> git grep '^ *[{}] *$' **/*.d | wc -l
>> 53126
>>
>> That's 16% of the total. Combined with empty lines, we're looking at a
>> 27.65% fluff factor. Isn't that quite a bit, even considering that
>> documentation requires empty lines for paragraphs etc?
>
> Just for fun, I decided to run these calculations on sumtype, which uses
> my own personal formatting style:
>
> Lines: 2389 total
> Blank: 435 (18%)
> Brace: 133 (6%)
> Fluff factor: 24%
>
> I'm clearly a lot less shy about using blank lines in my code than the
> average Phobos contributor, but I don't put opening braces on their own
> lines, so I end up with about the same level of fluff overall.
>
> I wonder if this is a coincidence, or if "readable" code in curly-brace
> languages naturally converges to around 25% fluff? Further research is
> needed.
I put blank lines everywhere. I need the fluff for it to look
reasonable. You will also see a lot of comments in my code too. I used
to do a 3-line comment using 2 blank // lines above and below, but I now
think a blank line (without the //) before the comment suffices. Meh, I
like readability, and I don't see the harm in it.
This is one of the largest rubble-bouncing threads I've seen in a while.
-Steve
More information about the Digitalmars-d
mailing list