In support of Instant.minus(Instant)
Louis Wasserman
lowasser at google.com
Thu May 2 17:28:53 UTC 2024
That doesn't follow for me at all.
The structure formed by Instants and Durations is an affine space
<https://en.wikipedia.org/wiki/Affine_space#Definition>, with instants the
points and durations the vectors. (An affine space is a vector space
without a distinguished origin, which of course Instants don't have.) It
is 100% standard to use the minus sign for the operation "point - point =
vector," even when "point + point" is not defined, and to use all the other
standard idioms for subtraction; the Wikipedia article uses "subtraction"
and "difference" ubiquitously.
Personally, I'd be willing to live with a different name for the operation,
but consider "users keep getting it wrong" a strong enough argument all by
itself for a version with the swapped argument order; it's not obvious to
me that another API with the same argument order adds enough value over
Duration.between to bother with.
On Thu, May 2, 2024 at 10:04 AM Stephen Colebourne <scolebourne at joda.org>
wrote:
> On Thu, 2 May 2024 at 15:58, Kurt Alfred Kluever <kak at google.com> wrote:
> > instant − instant = duration // what we're discussing
> > instant + duration = instant // satisfied by instant.plus(duration)
> > instant - duration = instant // satisfied by instant.minus(duration)
> > duration + duration = duration // satisfied by duration.plus(duration)
> > duration - duration = duration // satisfied by duration.minus(duration)
> > duration × real number = duration // satisfied by
> duration.multipliedBy(long)
> > duration ÷ real number = duration // satisfied by
> duration.dividedBy(long)
> >
> > All but the first operation have very clear translations from conceptual
> model to code. I'm hoping we can achieve the same clarity for instant -
> instant by using the obvious name: instant.minus(instant)
>
> But you can't have
> instant + instant = ???
> It doesn't make sense.
>
> This is at the heart of why minus isn't right in this case.
> Stephen
>
--
Louis Wasserman (he/they)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20240502/ef970768/attachment-0001.htm>
More information about the core-libs-dev
mailing list