Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87974 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19976 invoked from network); 1 Sep 2015 06:52:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2015 06:52:06 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.54 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.54 mail-pa0-f54.google.com Received: from [209.85.220.54] ([209.85.220.54:36494] helo=mail-pa0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 03/DA-39890-51B45E55 for ; Tue, 01 Sep 2015 02:52:06 -0400 Received: by pacgr6 with SMTP id gr6so15517143pac.3 for ; Mon, 31 Aug 2015 23:52:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=/FSzum5yBgH2tCQu+Yi4XyTq1grxDTjXeqaN7CBM0hk=; b=MwJcnMAA7tQMbcOmy668amOqzIiPdc1BAOjN910PsnGnpq3+4SP2BtVcDyLBcH77xB /tfFPpRh8BvxyopzsxCdyMAYqz9xIaj2tHugC5R0VSItXcsXoN8q2DjWy0PnN5zV2a3/ F/FJlKmgHByT7hS9DMCZheaA4cQjO1A4NauvDnYlGqPjVUAhVZmoq2ETG+z/TX1tr5Vc 3RfnHS0aeW+IUg/O2xlJxtQYXWlShrKhTfmlgElG740Qie5GoU2O1yYsMCjRiaof5HPO Kg8OPXsAB+qz7siVns3QgAj09LHAsgA3L2NwpibGEi9rUilZKFUtLU6+n05cc3WMMdJD bGVg== X-Received: by 10.68.233.134 with SMTP id tw6mr45643451pbc.22.1441090322456; Mon, 31 Aug 2015 23:52:02 -0700 (PDT) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by smtp.gmail.com with ESMTPSA id j4sm7714579pdf.74.2015.08.31.23.52.01 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 31 Aug 2015 23:52:01 -0700 (PDT) To: Anthony Ferrara References: <55E4C19F.4060704@gmail.com> <55E4F029.10104@gmail.com> <7BCB36EE-56C8-441F-BF40-954D9FA912A9@lerdorf.com> <55E51FAA.8030106@gmail.com> Cc: "internals@lists.php.net" X-Enigmail-Draft-Status: N1110 Message-ID: <55E54B09.3080007@gmail.com> Date: Mon, 31 Aug 2015 23:51:53 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] [Discussion] Short Closures From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > I agree that at first it will feel a little bit weird, especially > given that PHP in general lacks syntactic sugar (we still don't have a > short-hand to initialize stdclass objects). We introduced [] back in > 5.4, and largely it has made readability FAR better (despite some > people saying it wouldn't at the time). That doesn't mean now we have to drop all keywords and switch to write-only style. Even [] was somewhat controversial, though it is the most elementary syntax construct. Function call is in no way elementary - it has non-trivial structure, and obscuring this structure by removing keywords does not help readability. > tool isn't always appropriate in all situations. You can craft code > that makes this new syntax look unreadable. But you can craft code The problem is not that I can. The problem is that anybody can, and a lot of people would, unwittingly, once the expressions get more complex that $x+1. > that makes this look far more readable. > > Example: > > function partial(callable $cb) { > return function($left) use ($cb) { > return function($right) use ($cb, $left) { > return $cb($left, $right); > }; > }; > } It is a bit verbose but pretty clear what's going on here - function returns a function that returns a function, and you can easily track which variable goes where and how it gets to the end. > > vs: > > function partial(callable $cb) { > return $left ~> $right ~> $cb($left, $right); > } It looks very pretty as the ASCII art, and no entry-level programmer would have any idea at all what these arrows actually do and how this thing is supposed to work. At least not without studying the manual very closely for extended time. That's exactly the problem. People start writing overly clever code that looks so pretty - and then other people are left scratching their heads about what actually is happening there. That's what I mean by write-only code. > It may look weird at first, but consider that's because you're not > used to the syntax. To me, the top is far harder to follow because of Of course, with enough training you can get fluent even in APL. I know people that are. But PHP is supposed to be on the other end of the spectrum. > the shear number of tokens to follow, not to mention that I need to > pay attention to the use-blocks which may or may not be importing > certain variables. The bottom reads exactly how I would expect it to. That's because you wrote it and know in advance what it is supposed to do. It's not a good test of readability. -- Stas Malyshev smalyshev@gmail.com