Re: [PHP-DEV] [RFC] Duration class

[email protected] ("Larry Garfield")
Newsgroups php.internals
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.