Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126341 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id B17771A00BC for ; Fri, 7 Feb 2025 20:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738960970; bh=RvclNcOirZ8gNIu9ZZqy5q5ZK+m0aMPvFRifPs5voqU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hNLjvE/UPa9g+DyIA3617X6a8Y3vDUsLAObs2YupfK6i0bKFuGUWG5YRmHcWxKwMI MfsFqrOyuZ1gZYkXo5CT7/Y97A3AFXmG6RT01S7Z78JcdbN0Evh5SiMtohOpYkUF5S jILZnVMqijHMAUsm13R4Rk3yUVsIlAuDif1vAlL6peVBM25uwA+DCSPXQs0IUJcw1i dozJRXl/BAsitL4128Qz1B0vLWK6ySag/zFwKp3YH5tjNX+siIwcf+dNHllBJ0WBSr 7lH/nLzUU7RJSALdrsCUYjLkpSh9D2J1mPZKfWiFCX5Xr2Np9QY7nbt5DJlS46yRV2 B/ncyG16XNUAw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DA405180034 for ; Fri, 7 Feb 2025 20:42:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_INVALID,DKIM_SIGNED,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,URIBL_SBL_A autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from sender4-of-o54.zoho.com (sender4-of-o54.zoho.com [136.143.188.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 7 Feb 2025 20:42:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1738961132; cv=none; d=zohomail.com; s=zohoarc; b=J/J7UFbW50JMdamSI53T1hupiAV2MB+8QOHVdKPJz1uizr76nRvHyBX1Sp7e1J7xaBysk5N4s9akfkuFyk6yBobpBtWZ90A/5GW0FU5xob6BPaLYYYhnFMVsPyUOUSkxjcg5qTjGkwiWFGCU20aq+v5fFLhqh9lh0Kt8gLjnqWQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738961132; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=C+vK6kXoLAgaOG2/ryUFh9FBePEz1AOOlnhT0ESNQzk=; b=nd0n2RyjaatyCI7AG1rLabQScs9FVYoOAIcpBa8bcGzzObwe/hYc9bglLkRNsyN1xeRL48oc9p5y9r3ROa2RM24njzhmDjElx+HdN3irhIN6ijIHAYbjfb6Tg58eLc94cCyIbw/n1Dl/ht01lTWbgIFL/xVI9GTAPH9c94k933k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=faizanakram.me; spf=pass smtp.mailfrom=hello@faizanakram.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1738961132; s=zoho; d=faizanakram.me; i=hello@faizanakram.me; h=MIME-Version:References:In-Reply-To:From:From:Date:Date:Message-ID:Subject:Subject:To:To:Cc:Cc:Content-Type:Message-Id:Reply-To; bh=C+vK6kXoLAgaOG2/ryUFh9FBePEz1AOOlnhT0ESNQzk=; b=NlhfCjpQML5Tit9qm1Jq3vUvmTuTwpQOjbEdm7fpHXOPz5N7icvC9cz0God8ej+O fqCdh7eO6A+O5kgicIvi96jvdSeSKnRaL8JZKuv0a1PeIHkAnqrD/0TuEZ2+eXkDyd3 LUHQn3U8+oKCgsjZ2YqoA81wW0qFF/AwmuSH+bW8= Received: by mx.zohomail.com with SMTPS id 1738961128943339.07286042044507; Fri, 7 Feb 2025 12:45:28 -0800 (PST) Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e5b1c4d14f2so2243223276.0 for ; Fri, 07 Feb 2025 12:45:28 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXGpCUbiuRZjeKmNd2+JNM+WL5oDmKeKQhEQ5//m6Krt1hKxccnEwt3QgcO2ZiAA8PRKtF4k31VnEQ=@lists.php.net X-Gm-Message-State: AOJu0YyS8MMwoCxf9H7opGR7LSQlx4aHsMymDBcFzcTf/ZUzSzdrdNlB nfpsUmw2knnEX85F6WrhcHsbxxDy7Irt3BdpjNaBEcx1To0QH4LyX298qyVQHxyr0myJ+pX+icB ZZreRRFnZ11xuXJ9gthknzJ9gtus= X-Google-Smtp-Source: AGHT+IFbml8iADyi3FaZmhfOc9h26vElavph8w98pPFrxLDqke3zCGvd0C74k1I+1vSVGvf4SR+HN1MKPrwJnFwFgo0= X-Received: by 2002:a05:6902:120c:b0:e5b:44d6:b56a with SMTP id 3f1490d57ef6-e5b4618d5e4mr3779429276.20.1738961128514; Fri, 07 Feb 2025 12:45:28 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <38b57201-5091-4c68-988b-9ce3beac8fcb@cubiclesoft.com> In-Reply-To: <38b57201-5091-4c68-988b-9ce3beac8fcb@cubiclesoft.com> Date: Fri, 7 Feb 2025 21:45:16 +0100 X-Gmail-Original-Message-ID: X-Gm-Features: AWEUYZlDJUPGsCNj7hYIYjd_jfw6b8FW9t8av75eieZmSeJ6K3z9YzomhVwMglg Message-ID: Subject: Re: [PHP-DEV] [RFC] Pipe Operator (again) To: Thomas Hruska Cc: Larry Garfield , php internals Content-Type: multipart/alternative; boundary="00000000000057f787062d93702b" X-ZohoMailClient: External From: hello@faizanakram.me (Faizan Akram Dar) --00000000000057f787062d93702b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 7 Feb 2025, 21:27 Thomas Hruska, wrote: > The repeated assignment to $temp in your second example is _not_ > actually equal to the earlier example as you claim. The second example > with all of the $temp variables should, IMO, just be: > > $temp =3D "Hello World"; > $result =3D array_filter(array_map('strtoupper', > str_split(htmlentities($temp))), fn($v) { return $v !=3D 'O'; }); > Tbh, this is unreadable. Larry's example with an intermediate variable is a magnitude times more readable. This is exactly why we need pipe operator. I also consider the above compact code to be plenty readable and not > particularly necessary to span multiple lines, but that's obviously > subjective. > It is not, the functions are being applied from in to out (or right to left), which become hard to read with addition of each new function. Pipe operator makes it natural as they are applied from left to right which is how you read code, literally 0 cognitive load. Just because someone _can_ do something doesn't mean that they should. > More than likely, users trying to do pipe-like operations in PHP > shouldn't be doing them in the first place. > Why not? It clearly makes code more readable and in future with PFA (=F0=9F= =A4=9E) will allow composing non-unary functions. PHP is and always has been a multi paradigm language, there is no reason to not add stuff which makes using functional paradigm easier. Kind regards, Faizan --00000000000057f787062d93702b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Fri, 7 Feb 2025, 21:27 Thomas= Hruska, <thruska@cubiclesoft= .com> wrote:
The repeated as= signment to $temp in your second example is _not_
actually equal to the earlier example as you claim.=C2=A0 The second exampl= e
with all of the $temp variables should, IMO, just be:

$temp =3D "Hello World";
$result =3D array_filter(array_map('strtoupper',
str_split(htmlentities($temp))), fn($v) { return $v !=3D 'O'; });

Tb= h, this is unreadable. Larry's example with an intermediate variable is= a magnitude times more readable. This is exactly why we need pipe operator= .=C2=A0

I also cons= ider the above compact code to be plenty readable and not
particularly necessary to span multiple lines, but that's obviously subjective.

It is not, the functions are being applied from in to out (or ri= ght to left), which become hard to read with addition of each new function.= Pipe operator makes it natural as they are applied from left to right whic= h is how you read code, literally 0 cognitive load.=C2=A0

Just because someone _can_ do something doesn't mean that they should. =
More than likely, users trying to do pipe-like operations in PHP
shouldn't be doing them in the first place.

Why not? It clearly makes co= de more readable and in future with PFA (=F0=9F=A4=9E) will allow composing= non-unary functions.=C2=A0
PHP is and always has be= en a multi paradigm language, there is no reason to not add stuff which mak= es using functional paradigm easier.=C2=A0


Kind regards,
Faizan
--00000000000057f787062d93702b--