Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87966 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88908 invoked from network); 1 Sep 2015 00:24:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2015 00:24:23 -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.43 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.43 mail-pa0-f43.google.com Received: from [209.85.220.43] ([209.85.220.43:34956] helo=mail-pa0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 45/96-39890-430F4E55 for ; Mon, 31 Aug 2015 20:24:22 -0400 Received: by pacdd16 with SMTP id dd16so155372888pac.2 for ; Mon, 31 Aug 2015 17:24:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=svG29XOd6KWkh8VHCpjkM1M+Zx9L2KsHKkva++AxUY4=; b=YhJyQS8R1+kGCH1nRdHhWu0lYvgNrp0I+A2iYvgutrtG6U4GNt1aP6JoV88q7cU+8j 0mG145mI+0hI9fuaRqckC+zYd4m0oc3uNcz6TlmAm8A2A/ihf1d5ct1urLBqCF7NGh8g 7oR62gV1Q8ypjxeBt4voBLfIP4jMxZ1qC5MArU0Ui1SfFoc5Zk9QuRuPaDFRYWGVLdDW ceQ77tGgf9RPXD9AZdgTLuR934oybCQLqrL9M13ZbX+9+AwvY7wE552516A/liJFnEh0 XT6+e3YM30AVOQnXDpCMwmV8m/lN0lD3ujXUBReyDpYVHiOWq6SGrwWMOTRM7CDs7wH5 e38w== X-Received: by 10.68.236.194 with SMTP id uw2mr42026964pbc.84.1441067057516; Mon, 31 Aug 2015 17:24:17 -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 yu2sm16009398pac.33.2015.08.31.17.24.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 31 Aug 2015 17:24:16 -0700 (PDT) To: Nikita Nefedov , internals@lists.php.net References: <55E4C19F.4060704@gmail.com> X-Enigmail-Draft-Status: N1110 Message-ID: <55E4F029.10104@gmail.com> Date: Mon, 31 Aug 2015 17:24:09 -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=koi8-r Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] [Discussion] Short Closures From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > in this RFC. The main addition (which is extended by that btw) is making > the syntax shorter. Which, in turn, makes it easier to write and read Shrtr dsnt lwys mks thngs esr 2 rd. Sometimes it's quite the opposite. > It would be much easier to read and write with the short syntax: > > $collection = array_filter(array_map((Type $el) ~> $el->getStuff(), > $collection)); I disagree. It is very hard in this syntax so see where function call starts and where it ends, especially if there are more that one parameter and/or more than one closure. > Just because, I'll say it, the less symbols you have to read the faster > you'll read it. To some extent, of course, a counter-example being Perl > language. But I don't think that we are even close to it. Yes, in this instance we are. And that's not a good thing. > Your point about capturing too much if you have too much in the global > scope is legit but in this case I'd say two things: you can still use > long closure syntax, and second you have a problem with global scope not > short closures. No, I don't have a problem with global scope - this proposal has a problem with any scope that contains many variables. Actually, virtually every scope contains more variables than closures need. Without this capture there is no problem. > You see the main use case for anon. functions is when you need a > *lightweight* callback for something. If it were a fat function I'd And capturing whole scope makes it anything but lightweight, especially if you have big scope. > probably make it named and write tests for it. But when it's a small > function, often consisting from only one expression it kinda bothers me > when the body of this function takes less keystrokes than 'function' and > 'return' keywords... If keystrokes are a problem, there are lots of solutions - like IDEs that allow to define macros. Saving keystrokes at the cost of readability never was a principle in PHP, and I don't think we should start now. -- Stas Malyshev smalyshev@gmail.com