On Sunday, October 6th, 2024 at 13:16, Eric Sunshine <sunshine@xxxxxxxxxxxxxx> wrote: > ... it's subjective, but I find that placing the strbuf as the first > argument makes the purpose of the function less clear. The direct > purpose of all (or the majority of) functions in strbuf.h is to > operate on strbufs, thus it makes sense for the strbuf to be the first > argument (just like `this` is the invisible first argument of instance > methods in C++ which operate on an instance of the class). However, > infer_backlink()'s purpose isn't to operate on a strbuf; the fact that > the original signature neither accepted nor returned a strbuf bears > that out. The really important input to this function is `gitfile`, > thus it makes sense for this argument to come first. The strbuf which > this patch makes it use is a mere implementation detail (a > micro-optimization) which doesn't otherwise change the function's > original purpose, thus it belongs in a less prominent position in the > argument list. I can reverse the arguments. > ... this code now becomes more than a little confusing to read. It > says "if infer_backlink then signal error", which sounds rather > backward and leaves the reader scratching his or her head. ("Why > signal error if the function succeeded?"). Hence, infer_backlink() > should probably return 1 on success and 0 on failure, which will make > this code read more idiomatically: > > if (!infer_backlink(realdotgit.buf, &backlink)) { > ...signal error... This was my first thought, however, on unix it is fairly standard to return 0 if successful and a non-zero int if there's an error. I don't mind updating, but I want to follow what makes the most sense and would be most expected.
Attachment:
signature.asc
Description: OpenPGP digital signature