Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115115 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77547 invoked from network); 24 Jun 2021 11:46:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jun 2021 11:46:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 01B6E1804E3 for ; Thu, 24 Jun 2021 05:05:06 -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,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-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 ; Thu, 24 Jun 2021 05:05:05 -0700 (PDT) Received: by mail-ed1-f53.google.com with SMTP id h2so8183865edt.3 for ; Thu, 24 Jun 2021 05:05:05 -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=94apDedZOqVYs/iAKFI8KLaYeyL9fXKKCCxCbsYP0So=; b=B7BK83berBAElxLleQEw2NYxBKmbX6/DFfB8ZGY9T+v3FMWJSjZ7yc7t7adYuYA/OB CCij9FHF8U9S0r611fn8WUC/VAVJE5invwCiEyo25t70i/HK2TeEL0Hlzkt6O5LO2jcQ m4tC7kGmk7NherMZxwpa+1CBZnDp/7vFgWejYEz6kPu5FLLhrmJDVV80FAxYkLA/iIWV IE4aGWGZA/H1LLdbg4/9m5/CZz7ZqHcBmmEfSNpAtDVFz3RglWmut++GD3JJTsH8jbal 0DKfzaXEaXFbyKPogvCcFp64O3fvI07enDihzSM9F5HRXE1mfyGCYGsvxMAXADFDAZbE pzZw== 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=94apDedZOqVYs/iAKFI8KLaYeyL9fXKKCCxCbsYP0So=; b=EtZU08txIMikMHdP+jPKQxEzjLBnTQTpXEFpviUUA5oj2ME6gl5nJO3Adt6oY8/TIr NCPxrvw1IUIQgzSNDDvhty/ioU6EoozdECPNg0mNVFRnsU169dm0qSiTg2qxJ59apehK +qtzt2JLZX5DX936nWm7Hhke0TppFfZdc6PKYuuvhk7O2IBAJN0AyCX+/ZdOXW3KFAmt 1eUMUY8b+UhHsG0CH+9gFK3piiMXT//OSmxeo/gCq9Yz4HE4WCh8A/OoOjFXzraVmm1k V14+jsKRSA8OMYQM5W0CeYfsUG8HxUAGdvDo6NyxHbBq4BW4pGlVrT7gPYqAbdmlXpuz S+sg== X-Gm-Message-State: AOAM5333WpgyG2UEBJMvWz2kyzW/v13WiMcjyLx9C0KZGoLl9rAo+tr8 JrNd7u47bYuo0xqx4+KSlxCbvCj61FJRiWX9ZGU= X-Google-Smtp-Source: ABdhPJzT9IXKEHXqolJUpkdEv8IJlTACDb0MhAEV0uVOb6X8ZRBQRxxfU9eApJ/39ObKRUxL0tKul1wgP0zKaHKqGF0= X-Received: by 2002:a05:6402:397:: with SMTP id o23mr3720250edv.217.1624536303494; Thu, 24 Jun 2021 05:05:03 -0700 (PDT) MIME-Version: 1.0 References: <012901d7683a$446a7ba0$cd3f72e0$@gmail.com> In-Reply-To: Date: Thu, 24 Jun 2021 13:04:52 +0100 Message-ID: To: Hamza Ahmad Cc: Sara Golemon , Mike Schinkel , PHP internals Content-Type: multipart/alternative; boundary="0000000000004b680805c581d542" Subject: Re: [PHP-DEV] Introduce str_left/right In 8.1 From: george.banyard@gmail.com ("G. P. B.") --0000000000004b680805c581d542 Content-Type: text/plain; charset="UTF-8" On Thu, 24 Jun 2021 at 07:20, Hamza Ahmad wrote: > HI George, > > > I really don't see the point of these functions. > > These functions provide a clearer semantics for their usage. Are they though? The naming doesn't convey anything as pointed out by Kamil. > 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! > This is factually wrong, the first/last n characters of a string IS a substring of the original string. And by that logic left and right are actually linguistically incorrect due to languages being read Right to Left or Top to Bottom. > 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. > A language, be that spoken or programming, provides you with building blocks that you can combine to form larger constructs to express thoughts or a logical operation. Here you are basically asking to add a whole new set of half done constructions just because you didn't know a fundamental aspect of the PHP language, which is that string offsets can be negative, a fact that you can use broadly across the language. Now, why did you not know this is a more interesting question to solve, is it documentation? You never needed to do this before? etc. Moreover, the fact that only a very restricted number of programming languages, which are some of the earliest languages ever, implement those functions should tell you something about programming language design as a whole, which is that many people came to the conclusion that a variant of substring is a better abstraction than "left/right". I'll indulge you in my thought process which plainly is, "oh I'm extracting part of this string, oh this takes the first/last n bytes, fair enough", contrast this with how you'd need to perform str_contains() previously strpos($haystack, $needle) !== false "Okay I'm looking to find if a needle is in a haystack here, ... wait, am I because of the false? Ah no we're looking that it's just *somewhere* in the haystack" Which is fastly more complex and prone to logic errors if you need to touch this segment, a substring on the other hand, is always a substring. > 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. > Yes this requires an RFC, just by this thread alone you should realize this is controversial, and I'll personally vote against it because there is no advantage to have this in core at all. Regards, George P. Banyard --0000000000004b680805c581d542--