Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92990 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32281 invoked from network); 30 Apr 2016 15:52:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Apr 2016 15:52:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 212.232.25.162 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.25.162 mx206.easyname.com Received: from [212.232.25.162] ([212.232.25.162:34681] helo=mx206.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CE/2B-58459-8A4D4275 for ; Sat, 30 Apr 2016 11:52:09 -0400 Received: from cable-81-173-133-226.netcologne.de ([81.173.133.226] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1awXBd-0001CR-Et; Sat, 30 Apr 2016 15:52:05 +0000 Reply-To: internals@lists.php.net References: <8ea990da-1fe7-256c-4e08-0b30715c8e8a@gmail.com> <5724C9A7.5080504@fleshgrinder.com> To: Marco Pivetta , PHP Internals List Message-ID: <5724D490.6070500@fleshgrinder.com> Date: Sat, 30 Apr 2016 17:51:44 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="RPgHqHWrxhmkPIjBsGt88RJfsR9qMxDOI" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] [RFC] Pipe Operator From: php@fleshgrinder.com (Fleshgrinder) --RPgHqHWrxhmkPIjBsGt88RJfsR9qMxDOI Content-Type: multipart/mixed; boundary="PkW2TAqQQWR6PeMtBQgqsGUOKQhCIpKRI" From: Fleshgrinder Reply-To: internals@lists.php.net To: Marco Pivetta , PHP Internals List Message-ID: <5724D490.6070500@fleshgrinder.com> Subject: Re: [PHP-DEV] [RFC] Pipe Operator References: <8ea990da-1fe7-256c-4e08-0b30715c8e8a@gmail.com> <5724C9A7.5080504@fleshgrinder.com> In-Reply-To: --PkW2TAqQQWR6PeMtBQgqsGUOKQhCIpKRI Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 4/30/2016 5:23 PM, Marco Pivetta wrote: > This feature has nothing to do with fluent interfaces, nor has their fl= aws. > The readability of piped processing for functional code is simply a > no-brainer here, and doesn't require any API changes in function signat= ures > either: it is not "a different way of doing the same thing". > On Apr 30, 2016 17:05, "Fleshgrinder" wrote: >=20 This is the example code from the RFC written in a normal procedural way.= $files =3D scandir($arg); $files =3D array_filter($files, function ($x) { return $x !=3D=3D '.' && $x !=3D=3D '..'; }); $files =3D array_map(function ($x) use ($arg) { return $path . '/' . $x; }, $files); $ret =3D array_merge($ret, getFileArg($files)); This is the example code with the pipe operator. $ret =3D scandir($arg) |> array_filter($$, function($x) { return $x !=3D=3D '.' && $x !=3D '..= '; }) |> array_map(function ($x) use ($arg) { return $arg . '/' . $x; }, $$) |> getFileArg($$) |> array_merge($ret, $$); Definitely looks like "a different way of doing the same thing" to me. So does the initial super ugly example code of nesting. Again, I am not really against the proposal nor do I argue against the fact that it improves readability of certain code constructs. I am just meh on it because such code can pretty much always be rewritten in a way that makes it more readable, easier to debug, and even faster. In the example code we have: array_filter with O(n) array_map with O(n) array_merge with O(=E2=88=91 array_i, i !=3D 1) and in our case O(n) wher= e n equals the total count of elements in $files/$$. In my universe `getFileArg` (note the absence of a plural form) would operate on a single path and not on an array of paths: foreach (new DirectoryIterator($arg) as $path) { if ($path->isDot() =3D=3D=3D false) { $ret[] =3D getFileArg($arg . DIRECTORY_SEPARATOR . $path); } } I cannot tell if this construct is really equivalent to the example from the RFC (because I do not know what $ret contains) but it should do exactly the same. It is more readable, easier to debug, and much faster. Now you may argue that the example is simply flawed. Well, maybe, but functional programming is nice if you have a language that is functional. The only functional part in PHP are callbacks, everything else is just plain old procedural + OO and importing more functional concepts will not change that. However, I am not saying that every functional concept makes no sense just that the pipes are not very appealing to me because I only see "a different way of doing the same thing" with slower code. :P --=20 Richard "Fleshgrinder" Fussenegger --PkW2TAqQQWR6PeMtBQgqsGUOKQhCIpKRI-- --RPgHqHWrxhmkPIjBsGt88RJfsR9qMxDOI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXJNSYAAoJEOKkKcqFPVVrU9gQALxs4c3RTXlqoZDgI/jHFfJ/ WdAyTf/sC2K1j9qrRPn1TjlyFSrQHgqANBAHiMMZgPrAC7wgNPkI3cWxBkwtRRDL Z4ZQNp0eqYuHBAyMwdG0SiI7lylntcjjnLy2WZG6mnk5uabbW2KNLRLFuQ8j0l0k 1/SwCWHc2Y4X5axoocMGAvjhPeDlexJji9kGo/z6Xw2jkjc2McEKn5DnMEAaNvyo XNDFAHycT0CIBe7DUytP/22sSRRp84GsRS1rCOvpaeEDzML/VpqCDJTndKMx+/Wg Un/S0tHnCdXnfUVBjlioUb7j2+bWztPMYT56cAamvn0Cel5Fq5TdZn1ym3YSnvHP 1Dm9Lu1c8Jfe4ELZkoOUuFIXB1E5v/XSlr/09mxKHxPq2XZvb7QP83L+KdggqRXX v4uqe8JJbJ0LiGRt51Npsy7bIFyJhNoKdbHZuaEYFA6egFXvNUWLIHIY1DlV+J8U yfQIGwBP8LYgTkcXL83tIElhIGFZNEnFdqWcXYHXA4r7D8GCGSY9c3fnz1qsjd3R 5xa8QQgMk2akpNYOSGHOgV16dSMHFkiDarv+0g371mlEpPRrBvSRKS31uiO9JPwK 35WhsGGWuksOrhKlSctpaqW5xSC9bK+rhuGI0lfkY4g1povINLIiLQV3g2XTMX5S Aycpj+0NV4TCx9js2HGu =F5T3 -----END PGP SIGNATURE----- --RPgHqHWrxhmkPIjBsGt88RJfsR9qMxDOI--