Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115053 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 84516 invoked from network); 23 Jun 2021 08:10:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Jun 2021 08:10:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 83601180507 for ; Wed, 23 Jun 2021 01:28:29 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f48.google.com (mail-io1-f48.google.com [209.85.166.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 23 Jun 2021 01:28:29 -0700 (PDT) Received: by mail-io1-f48.google.com with SMTP id i189so2302495ioa.8 for ; Wed, 23 Jun 2021 01:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RPqaHQSl9Z2SD1iIn9opZVHWi9LLduD8JTLYsN1KFH4=; b=QCIcSK5xkmsjWU5OLVsZ693z5wXjZRG/+lypt7UDYF/QiRASw+zAyCtAPRxw+X7O5D osi4jqFQXFfDT3kdNt0amC1YCGiYoVwkFz7yjjo66b9JxhxuvKSI96gDxJxbYMOYBMq0 X7sUT3bQnrXwU1kBpqmesQSJiKx0aFJAZ9XSsxsUf58AbuS6Q0Q9q2DtNrWGRXaSngQW jhqw3viTxcehYHFd9cP2HyX4IpToPX3Zicsbu3bsbji34zvV86aoKnsOt+zItJO2PRBn Ab5iu5n/MrAqkzVizMT+PFYCj/LzUNvmpDe6pYMUz0nkHB4JeQiJa7L8ek3cECxSXTol 28rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RPqaHQSl9Z2SD1iIn9opZVHWi9LLduD8JTLYsN1KFH4=; b=D/+Lh9hdKReqPEX9kwL8WLRCebYA1NX5CkXuyWDOgFKn7UW1APVHhViM5Rd3zlQyz4 FBS92AftKeozUgA5kX4bOBzYycY2jrLC6Yo4j1oR5FrecM8/Bk8kxdKhRc5taVKTn7G+ KSqeoZ6LiU6GXAH9S/OWNUMSjZxZzmT0iTaANSZWnWVp5hjr6KR71rvcWjHgTV756S7j Khc+7KLk+gdOa9ZtWD+brpNAJjGBWLOPy2dQcq0HL38jXiWFgoArRuMzhd5BEwPExVuu i9QUfL/6nQrR8JZf4MCwzeaxI+4tIB+l8+vG9BMbgJnL5yjxnDwGoNrBUk3iDumHjsBm G2ww== X-Gm-Message-State: AOAM532C+rRY+2TC8b2i67REXitzv7ehAXK9vp4Cl3jjVW7R1I7AepZQ /MYAggJ6IdNoIO5ljb/wO/nHpfugK0Q7WD6Qdco= X-Google-Smtp-Source: ABdhPJzlHQdt4hrvGBly22nOsbcQ8e9TZo5vb7CfWeiWkKDH+sfnU7w+xoOdKO5WM53r5L+/sQQfGu4MPVThgZo15Ys= X-Received: by 2002:a5d:80c8:: with SMTP id h8mr6129286ior.120.1624436905895; Wed, 23 Jun 2021 01:28:25 -0700 (PDT) MIME-Version: 1.0 References: <1014AE76-B3D5-48F7-A0F0-B8E3327123A2@gmail.com> In-Reply-To: Date: Wed, 23 Jun 2021 10:28:00 +0200 Message-ID: To: Marco Pivetta Cc: Kim Hallberg , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000bc6b7505c56ab089" Subject: Re: [PHP-DEV] Proposal: clamp From: kjarli@gmail.com (Lynn) --000000000000bc6b7505c56ab089 Content-Type: text/plain; charset="UTF-8" On Wed, Jun 23, 2021 at 3:07 AM Marco Pivetta wrote: > The problem is exactly the fact that it is trivial to implement in > userland: why not do it there instead? > My 2cents: because people won't use it when the barrier is too high to get it. There are a ton of great libraries that have functionality like clamp, and some more elaborate, like an array replacement. In the end -based on my experience- people go to the php documentation and look for functions that they can use, or they use their IDE autocomplete functionality to see what's hinted at. Having these functions spread through the ecosystem means discoverability is low. I've needed the "clamp" function in the past and didn't even consider looking for a library to do this for me. Why would I even install a library to have a single function anyway? It feels like a massive overhead. I've seen coworkers use funky SPL functionality I didn't even know existed to avoid using external dependencies that have already solved their problem in a neat way, which were in fact already installed through composer. They found the solution through google and ended up in the official php documentation. I'd love to see these small additions in the core, they make the language feel more complete. The fact that they are easy to implement in userland means that we can have great forward compatibility through polyfills and already start using them in codebases that haven't been upgraded yet to the latest PHP version. I've been very happy to have been able to use str_starts_with, str_ends_with, and str_contains in 7.3, as they came in with a generic php polyfill. With a "see also: clamp" in the min/max function documentation, this would be easy to find as well. --000000000000bc6b7505c56ab089--