Subject: Re: [PATCH v9 9/9] cocci: allow padding with `strbuf_addf()`

From: Junio C Hamano <[email-masked]>
Date: Mon, 10 Jan 2022 09:47:44 -0800

Johannes Schindelin <[email-masked]> writes:

>> [...] about the using "strbuf_addf(line, "%7s" , "-");" or
>> "strbuf_addstr(line, "      -");". [...]
>>
>> Why I prefer more of the former that is because, for the single line,
>> it's more readable I think.
>
> I strongly disagree. Using a format requires the reader to interpret a
> `printf()` format, to remember (if they ever knew) the rules about padding
> with `%<number>s` formats, and then to satisfy themselves that the result
> is correct.

Both "more readable" and "cognitive load" are quite subjective.

FWIW, I have a slight preference to the former because I do not have
to count the whitespaces to figure out at which column the construct
is trying to align to.  Most of the time, however, I may not deeply
care if the thing is aligned exactly, and "     -" might be easier
to scan and getting alarmed by seeing "%7s" to wonder if there is
something unusual going on.  When I am reading not for finding out
the precise output format but for general correctness, bunch of 
unknown number of spaces followed by a dash might be easier to see.

But once you know the language, "%7s" is not so alarming, and it
does make it easier to see both for casual scanning and for counting
columns.  It also is likely that those who know the language would
make more efficient developers to fix and/or enhance the code, so I
prefer to optimize the code for them.