Re: [PATCH v2 1/4] worktree: refactor infer_backlink() to use *strbuf
- From
Caleb White <cdwhite3@pm.me>
- Date
- Oct 7, 2024, 02:42 UTC
- Message-ID
- <LyrqJt-X7sHVSKc-97V4-hTsDiIuz8ucEUMDtLCPWAN15k31EBjZnbeuJ2PldcCVvZaPyudvgb3H00T6uZQsI-XON7Ku8jNFjkfRCgrdr8U=@pm.me>
- In-Reply-To
- <CAPig+cSe0ykN=Mmb8Nwp112ROOCuhzzP0jofvL91PsVi8W4dHg@mail.gmail.com>
On Sunday, October 6th, 2024 at 13:16, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 14 quoted lines
> ... 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.
Show 7 quoted lines
> ... 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.