Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115094 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28710 invoked from network); 24 Jun 2021 06:02:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jun 2021 06:02:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7B8311804DA for ; Wed, 23 Jun 2021 23:20:49 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-ua1-f49.google.com (mail-ua1-f49.google.com [209.85.222.49]) (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 23:20:48 -0700 (PDT) Received: by mail-ua1-f49.google.com with SMTP id e7so1789607uaj.11 for ; Wed, 23 Jun 2021 23:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=+Cr2VrhnsNclehKrYAKSmU7agPU2zpiNJRSSyIaILVs=; b=aAAVCVKeTtgOSDT/NQtvEk9AWIFL+gY9LvXaxYTyZPzJEnP3QfvIctgPjcrTmHf7fL nj4yE7Dw33wPHR1pYKlULb/IA5/41D5/Dn5RSkcKvzYRFK3ON4kHioribP87ZK0a6lTM YVWAuEgD7yKvyxnxbrPekzoR6ZVxJztQtgq5BrzPe5gBtEIy9EfKhiCXWAlOkl68uXBc kZQ5PAsEjtrgEiyJefpAydZhOGO9WcZDzVgqentYygmEDHrKg8efiaui1uykCQVK6dnf RLQqtm/J3gd9jfGlA6tzkx3Ogx7PxUogSVhonMm7eTgTWHq6f4/YRVDq1HhIiraUCwWS ra0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=+Cr2VrhnsNclehKrYAKSmU7agPU2zpiNJRSSyIaILVs=; b=hP5YoQ8KFKFBQzBgnwCWvj8c0Hds/c/XZ/4ViEDnz6ywXCYJ5rYINGKPefxHHqvuK4 MB0SHEFmNFPStV/1Z0M8nqWtgx4q7Xyw+dJquNX6uPBJs+xaGJ+WGXGWw5svuXdcHmnU x5w+w+/M+sO/si2dYzUzUnyKnEP3F/EUNKRE9xJg5juL7C/xSeokaLLwCgQyu/HjjOcH SC/K/EjuCTZU2FCMzXMiSKAneI0FEUpqqys/x0ffzl0MWdfr9CECJ0KQtWa/ddrjO85U Cg4Bt/q+b+VL8KcG4uyXvSxhyk5SalrfxEOPVQz59HiEfgIsR12sAqEbHgtxQ6kEiQbY QXlw== X-Gm-Message-State: AOAM530RwnAh9OCEa46HjhwR/XKWQ2k84VqiBnsACPaBiEjoO9H8+Tam EdliPLQM961uuIUR5vYy5eOGoOAqNtfMEIgd1Ko= X-Google-Smtp-Source: ABdhPJz+/dunLg0nRTuHMDkhLqHOT74G4P2CN+Ls9fCATWCxeJbdS2dJIhDjC22RBH/urPAl4uMM0/K1MtvCIQ/i5/g= X-Received: by 2002:ab0:3734:: with SMTP id s20mr3977736uag.106.1624515646568; Wed, 23 Jun 2021 23:20:46 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab0:3b8f:0:0:0:0:0 with HTTP; Wed, 23 Jun 2021 23:20:45 -0700 (PDT) In-Reply-To: References: <012901d7683a$446a7ba0$cd3f72e0$@gmail.com> Date: Thu, 24 Jun 2021 11:20:45 +0500 Message-ID: To: Sara Golemon Cc: Mike Schinkel , "G. P. B." , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Introduce str_left/right In 8.1 From: office.hamzaahmad@gmail.com (Hamza Ahmad) To George, et al, HI George, > I really don't see the point of these functions. These functions provide a clearer semantics for their usage. Substr, as Sara has mentioned, can be an alternative to these functions. Does it make clear that substr returns the either ends of a string? No, substr returns a part of a string, not ends. Although both mean similar, and substr can be used in absence of these functions, saying so is not linguisticly true! If these functions are added, one can make sense of what these functions actually do, without involving extra thought process. Furthermore, it will help code readers decode their purpose at the cognitive level, and that will provide with a faster understanding of the code. Therefore, Microsoft is using AI to design a clearer language to aid human minds understand quickly. I don't know how your mind functions, but allow me to explain my thought process. When I see substr, my mind says it is going to be a part of string from x offset to y offset. Then, I look at the offsets, I learn that it is either going to be a left end or a right end. If these functions are added to PHP, programmers will have a clear idea of what is going on there using a single thought. You are free to accuse me of mixing both psychology and computer science. HI Sara, > you didn't explain what they're meant to actually do. I thank you for pointing this out and also providing with the userland examples of these functions. As for the second function, I myself some time ago learnt that negative indexes are supported in substr. When I wrote this function for the first time, I used some other technique. As I have explained above that these functions are too common and useful, I don't find any big issue if these functions are added to core. IN VB, both mid and left/right functions exist. Hi Guilliam, > I think that's more about "semantics" ("conveying intent to readers") than typing... True, this is the main objective and motivation. Please, see the second paragraph that I dedicated to George. Hello Mike, > str_right() would provide an obvious solution that would be easy to find in IDE autocomplete or... I thank you for adding to the discussion. When I first time felt the need of str_right, I wrote this in a following way. ``` function right($str, $num) { return substr($str, strlen($str) - $num); }; `` Your opinion has strengthened my argument in three respects. First, these functions are often searched for and wanted in the community. Second, these functions will make the semantics clear. Third, these functions are too clear in their signatures and purpose, and one would hardly need to modify them. Nor, we need to add extra parameters and introduce new behaviors, like JSON indentation RFC. As for multibyte string functions, this is another domain. IF one wants to add mb_ these functions, it can also think of. Hi Christoph, > substr() is about bytes, not characters. Yes. Because PHP has MB string functions separately, implementation of these functions will be once for all. There will hardly be a need of touching these functions again. Hi Rowan, I thank you for providing with an other opinion. Here, I am only talking about the basic string functions. As for the MB functions, I am sure if these functions are added to core, they will also acquire their place in mb_* functions list. Because the time is approaching, what do you all suggest whether this request requires an RFC? I thank you all for providing me with your opinions. I wish this thread leads a positive consensus. Best Hamza Ahmad On 6/24/21, Sara Golemon wrote: > On Wed, Jun 23, 2021 at 2:10 PM Mike Schinkel wrote: > >> I have frequently heard the justification of maintenance burden mentioned >> as an objection to adding specific features. And in many cases, it is >> easy >> to see why future maintenance burden would be a concern. >> >> However, it *seems* in this case that these functions are so trivial to >> implement that once written and documented they would likely never need >> to >> be touched again. But as I do not yet know the internals of PHP I >> obviously >> do not know that to be a fact. >> >> Honest question: Would you mind explaining the type of maintenance >> required for simple functions like this? What is likely to change in the >> future that would require maintenance? And would you mind giving a few >> or >> at least one example of a trivial function that did need to be maintained >> after it was written? >> >> > Honest answer. I won't personally feel any pain from adding these > functions. No more than I felt when str_contains() was added over my > objections. Nobody maintaining PHP will feel significant burden from > them. They'll sit in ext/standard/string.c doing their trivial work, > opaque to the jit, and they'll get used or not. If cluttering the kitchen > sink with one more unwashed utensil makes someone happy, then fine. I'm > not going to vote for it though, because it belongs in composer/packagist > land, not in core. I've listed the reasons for this in the str_contains() > threads, feel free to reference those, they're still valid and correct. > > -Sara > > P.S. - I don't actually think the octet versus codepoint versus grapheme > argument can be particularly persuasive given that our core string > functions aren't encoding aware in the slightest. That ship has sailed. > It is, however, another argument for doing this in userspace where the > tradeoff is far more obvious, and dealing with alternative multibyte > engines and/or polyfills is much more facile. >