git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/1] Add a helper to reverse index_pos_to_insert_pos()

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 9, 2019, 08:17 UTC
Message-ID
<nycvar.QRO.7.76.6.1910091015090.46@tvgsbejvaqbjf.bet>
In-Reply-To
<623fcd51-5f0d-bc5b-f70d-0224a054ec5c@kdbg.org>
Hi Hannes,
On Wed, 9 Oct 2019, Johannes Sixt wrote:
Show 8 quoted lines
> Am 09.10.19 um 03:19 schrieb Junio C Hamano:
> > Johannes Sixt <j6t@kdbg.org> writes:
>
> >  After all, the primary purpose of
> > inventing the encoder was to catch the arith overflow, wasn't it?
>
> That was *your* motivation for the helper function. But IMO it is a
> wrong design decision.

I wish that comment, and the argument following it, would have come as part of the review of the patch series that already made it to `next`.

FWIW I actually agree with Junio about the helper, but in hindsight I could have used a better name (not one that is tied to the "index"). Something like `unsigned_one_complement()`. But of course, that would say _what_ it does, not _why_.

And yes, I would wish we had C++ templates so that the helper could use the exact type of the caller.

Ciao, Dscho

Show 19 quoted lines
> Whether or not the index calculation overflows is a matter of the type
> that is used for the index, and that in turn is dicated by the
> possible sizes of the collections that are indexed. IOW, the index
> overflow check is (*if* it is necessary) a policy decision that must
> be made at a higher level and must not be hidden away in a helper
> function whose purpose (as suggested by its name) is something
> entirely different.
>
> Unless, of course, we declare "all our indexes are of type int". But
> that ship has sailed long ago, because there are too many cases where we
> are forced to use size_t as index (strlen, sizeof...).
>
> Meta note: We know that we are painting a tiny shed here (Replacing a
> one-liner by a one-liner, huh?) If anyone of you has better things to
> do, please move on. My interest in this discussion are just the design
> decisions that are made, not the actual outcome of this particular case.
>
> -- Hannes
>
Previous: Johannes SixtNext: Junio C Hamano
Message 6 of 11 in “Fallout from azure-pipelines-msvc”
  1. 0/1 Fallout from azure-pipelines-msvcJohannes Schindelin via GitGitGadget, Oct 8, 2019
  2. 1/1 Add a helper to reverse index_pos_to_insert_pos()Johannes Schindelin via GitGitGadget, Oct 8, 2019
  3. Johannes SixtOct 8, 2019
  4. Junio C HamanoOct 9, 2019
  5. Johannes SixtOct 9, 2019
  6. Johannes SchindelinOct 9, 2019
  7. Junio C HamanoOct 9, 2019
  8. Johannes SchindelinOct 9, 2019
  9. Junio C HamanoOct 9, 2019
  10. Johannes SchindelinOct 9, 2019
  11. Johannes SchindelinOct 9, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.