Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92963 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54286 invoked from network); 29 Apr 2016 23:37:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2016 23:37:25 -0000 Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.106 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.106 blu004-omc2s31.hotmail.com Received: from [65.55.111.106] ([65.55.111.106:52923] helo=BLU004-OMC2S31.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 66/EC-26386-430F3275 for ; Fri, 29 Apr 2016 19:37:25 -0400 Received: from BLU436-SMTP216 ([65.55.111.72]) by BLU004-OMC2S31.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Fri, 29 Apr 2016 16:37:22 -0700 X-TMN: [iCIgOK3V7Zz0LxfrnSVxiutf3PCkVcwh] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 (Mac OS X Mail 9.2 \(3112\)) In-Reply-To: Date: Sat, 30 Apr 2016 01:37:17 +0200 CC: PHP internals Content-Transfer-Encoding: quoted-printable References: To: Sara Golemon X-Mailer: Apple Mail (2.3112) X-OriginalArrivalTime: 29 Apr 2016 23:37:20.0161 (UTC) FILETIME=[128B4910:01D1A270] Subject: Re: [PHP-DEV] [RFC] Pipe Operator From: bobwei9@hotmail.com (Bob Weinand) Hey, > Am 29.04.2016 um 21:58 schrieb Sara Golemon : >=20 > This is one of my favorites out of HackLang. It's pure syntactic > sugar, but it goes a long way towards improving readability. > https://wiki.php.net/rfc/pipe-operator Thanks for proposing, so that I am able to show what I don't like about = the |> pipe operator: In general, the pipe operator is hiding anti-patterns. It makes = anti-patterns look nicer. Take the first example: $ret =3D=20 array_merge( $ret, getFileArg( array_map( function ($x) use ($arg) { return $arg . '/' . $x; }, array_filter( scandir($arg), function ($x) { return $x !=3D=3D '.' && $x !=3D=3D '..'); } ) ) ) ); Sure, it *looks* nicer with the pipe operator, if you really want to = nest it. But that nesting is horrible in itself. It should be written = as: $files =3D array_filter(scandir($arg), function ($x) { $x !=3D '.' && $x = !=3D '..'; }); $fullPath =3D array_map(function($x) use ($arg) { return "$arg/$x"; }, = $files); $allFiles =3D array_merge($allFiles, getFileArg($fullPath)); By limiting the nesting level to 2, the code gets itself much more = readable and in addition, the variable names are self-explaining, so = that you can jump right in. As already mentioned, the |> variant looks nicer than the above, but it = still lacks the most important part; documentation in form of obvious = variable names after each small step. It's always nice when code can look nicely, but this doesn't encourage = writing understandable code. This RFC is just providing another way to = shoot any future readers into the feet. Readers want to quickly grasp what is going on. Having to follow a whole = list of operations whose result is written to a variable $ret is telling = them absolutely nothing. TL;DR: -1: The |> pipe operator encourages a write-only style. Bob=20=