Re: [PATCH v9 9/9] cocci: allow padding with `strbuf_addf()`
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Jan 10, 2022, 18:02 UTC
- Message-ID
- <220110.86ee5fzcsi.gmgdl@evledraar.gmail.com>
- In-Reply-To
- <nycvar.QRO.7.76.6.2201101346090.339@tvgsbejvaqbjf.bet>
On Mon, Jan 10 2022, Johannes Schindelin wrote:
Show 20 quoted lines
> Hi Teng, > > On Mon, 10 Jan 2022, Teng Long wrote: > >> [...] 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. > > That's quite the cognitive load you put on the reader for something as > trivial as " -". > > Not a fan, > Johannes
I think you can argue that, but saying that this series must change that existing "%7s" format just because it happened to trip over an existin coccinelle rule as code was changed from printf() to strbuf_addf() is going overboard.
Also, the ls-tree output has existing alignment issues, and the documentation says:
"right-justified with minimum width of 7 characters"
So I'd think we'd want to keep the %7s, and in some future change change that format to be dynamic so we'd align things properly if some fields were longer than 7 characters.