Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87975 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22180 invoked from network); 1 Sep 2015 07:04:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2015 07:04:16 -0000 Authentication-Results: pb1.pair.com header.from=laruence@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=xinchen.h@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.213.43 as permitted sender) X-PHP-List-Original-Sender: xinchen.h@zend.com X-Host-Fingerprint: 209.85.213.43 mail-vk0-f43.google.com Received: from [209.85.213.43] ([209.85.213.43:35121] helo=mail-vk0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/3B-39890-DED45E55 for ; Tue, 01 Sep 2015 03:04:13 -0400 Received: by vkaw128 with SMTP id w128so51272251vka.2 for ; Tue, 01 Sep 2015 00:04:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=wrkfQkQVPQPml88I49893ByPDIKooPPVQa2jl1l/sH0=; b=gr/+0kNLPurEly5VY+MmOzup8EYyK33mFDLZ6+Dy7JjWVYpy7oKRl3ThULhaeOQQB3 f0mySQ7H5ak/60Br6gUTrW2cf/Qb7vlQHPfRuo+CkM82JaLys2dYjb+laUEtuH12r5xw JSJHbvmRNb2hI84Dt8dUL5jXGvbwl+T7w4Sn7P1V/xDHxQfTiFEM525Yposw74Tss2WR dFQDDHviCLDOR1fPkFuQks7VAQPtmJl4a5SzwUSHQNdzwEBXhr/2tlZ/FaNzuUzfz8fF Y3047oRzSgFYChknjnyM87yEcysWwhLMnnxsaZl7RRd8PK/SCWSh0+t2uYqvIFfvmMcC EL8w== X-Gm-Message-State: ALoCoQnfmrcq8mF10p9kGuH/biRetwQvotk0aH+XkU39cLz1s/wxxBiLhM1Ko1Ic1npeutxwF2E+irGvottPHnkt349bBosyoox8mEAsZKLk1LBYAq/K7ye+fiaFYExgphlH4dMI2PqqIaV8GRu7RdFHdZj6U+U0WMD0HeTuWL1kZAsx6ujP0Lk= X-Received: by 10.53.11.226 with SMTP id el2mr28352306vdd.37.1441091050576; Tue, 01 Sep 2015 00:04:10 -0700 (PDT) Received: from mail-vk0-f50.google.com (mail-vk0-f50.google.com. [209.85.213.50]) by smtp.gmail.com with ESMTPSA id r1sm3257101vdc.13.2015.09.01.00.04.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Sep 2015 00:04:09 -0700 (PDT) Received: by vkhf67 with SMTP id f67so51572763vkh.1 for ; Tue, 01 Sep 2015 00:04:09 -0700 (PDT) X-Received: by 10.52.110.5 with SMTP id hw5mr7632046vdb.7.1441091049737; Tue, 01 Sep 2015 00:04:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.53.75 with HTTP; Tue, 1 Sep 2015 00:03:50 -0700 (PDT) In-Reply-To: <55E54B09.3080007@gmail.com> References: <55E4C19F.4060704@gmail.com> <55E4F029.10104@gmail.com> <7BCB36EE-56C8-441F-BF40-954D9FA912A9@lerdorf.com> <55E51FAA.8030106@gmail.com> <55E54B09.3080007@gmail.com> Date: Tue, 1 Sep 2015 15:03:50 +0800 Message-ID: To: Stanislav Malyshev Cc: Anthony Ferrara , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] [Discussion] Short Closures From: laruence@php.net (Xinchen Hui) Hey: On Tue, Sep 1, 2015 at 2:51 PM, Stanislav Malyshev wrote: > 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. +1, that is what readable(guessable) means..... thanks > -- > Stas Malyshev > smalyshev@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php -- Xinchen Hui @Laruence http://www.laruence.com/