Hi

Am 2026-06-22 20:52, schrieb Larry Garfield:
> However, I would advise against introducing Duration::add and
> Duration::sub
> methods. Instead, I would recommend providing a single method,
> Duration::sum(Duration
> ...$durations): self.
>
> […]
[…]

I am 100% against a static method for adding durations. That's entirely pointless. Even if we're just using methods and not operators, $dur3 = $dur1->add($dur2) is the way to go.

Both Derick and I were receptive to the `Duration::sum()` suggestion.

One big benefit I am personally seeing is that it would allow to rename the `negate()`, `multiplyBy()`, and `divideBy()` methods to use “past tense” (is that the correct term?) to indicate that they return a copy, without requiring awkward naming like `added()`. `->sub()` is also technically redundant due to the existence of negative Durations, thus there is no need for a mirrored pair like multiplication / division, since the information can be encoded in the Duration object itself.

To avoid readers making assumptions, can you spell out your arguments against replacing `->add()` and `->sub()` by a unified `::sum()` method?

Best regards
Tim Düsterhus

Reply via email to