Re: [RFC] Duration class

From: Date: Thu, 02 Jul 2026 18:56:02 +0000
Subject: Re: [RFC] Duration class
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-131721@lists.php.net to get a copy of this message
On Thu, Jul 2, 2026, at 1:30 PM, Tim Düsterhus wrote: >> negated() would be consistent with the "ed means return new" pattern >> found in many languages, so I would strongly recommend following that >> pattern. > > Yes. The only issue I'm having with that is that it doesn't trivially > transfer to addition and subtraction, which technically would be an > inconsistency in the API. Maybe that's okay, particularly given that > both Java and JavaScript have the -ed for everything exception addition > and subtraction, but I nevertheless want to have the discussion. From what I've seen in my collections research, the -ed suffix is used in cases where it's not obvious from the method name. (For some definition of obvious.) For instance, append() tends to be an operate-in-place, and concat() produces-new. But neither have an -ed on them. Things like sort[ed]() or reverse[d]() do, and often have both versions on the same object. So I think a reasonable guideline is "if it's self-evident, don't bother; if it's confusing, use -ed for the return-new immutable one." For some squishy definition of self-evident. In this case, it feels self-evident to me that add() will return-new, as that's how I am used to addition working. incrementBy() I would expected to modify-in-place. negate() is potentially confusing as it could go either way, so I would recommend the -ed suffix. --Larry Garfield

« previous php.internals (#131721) next »