Re: [RFC] [Discussion] Add clamp function
| From: | Larry Garfield | Date: | Wed, 27 Aug 2025 16:40:51 +0000 |
| Subject: | Re: [RFC] [Discussion] Add clamp function | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128574@lists.php.net to get a copy of this message | ||
On Wed, Aug 27, 2025, at 11:06 AM, Bob Weinand wrote:
> Hey,
>
> On 27.8.2025 15:34:53, Kyle Katarn wrote:
>> Hello,
>>
>> I handled the feedback received on the draft RCF
>> https://wiki.php.net/rfc/clamp_v2
>>
>> If I didn't forget anything this should be now ready for discussion. So I updated its
>> status.
>>
>> There is an implementation proposal:
>> https://github.com/php/php-src/pull/19434
>> And some draft for documentation here:
>> https://github.com/php/doc-en/pull/4814
>>
>> Thanks,
>
>
> As others have noted before, what's the motivation of having the
> to-be-clamped value as first parameter rather than infixed between min
> and max?
>
> E.g. from CSS:
> https://developer.mozilla.org/en-US/docs/Web/CSS/clamp:
>
>
clamp(min, val, max)
>
> Feels to me as the most natural order, too.
>
>
>
> You mention it was taken from the first RFC, but that one also did not
> discuss the ordering in the first place either.
Some quick data points from momentary googling:
CSS: clamp(min, val, max)
Python: clamp(val, min, max)
C++: clamp(val, min, max)
Java: clamp(val, in, max)
Javascript: clamp(val, min, max)
C#: clamp(val, min, max)
Kotlin: val.clamp(min, max) (as an extension function)
Ruby: val.clamp(min, max)
So it looks like CSS is the oddball here. We should follow the clear majority approach. (Kyle,
feel free to include this in the RFC.)
--Larry Garfield