Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98071 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86344 invoked from network); 31 Jan 2017 11:53:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2017 11:53:54 -0000 Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.219 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.219 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.219] ([81.169.146.219:32704] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/03-51557-0DA70985 for ; Tue, 31 Jan 2017 06:53:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1485863630; l=9998; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:References:In-Reply-To: MIME-Version; bh=x8iWLbT2JfzTzks9evVc4I56SSl52SGt2kzWgo2zpjc=; b=wOpWKk83DAxbkcajKU4S2o4B/IB2EQ1Az1ESZMcrSG2kzawXuTISrMyo5iA4ZLZVRY qIErja67UgRjfGuXT7lAkT+h2zbyiLj96ndouu1wrrGy9O5hhmKll54WNS7PmCbuBPXp z3OZth/fII0BWDN73eiznjot2qtniuWM4hBVQ= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLDup6E67mzuoBPBqD/sh4= X-RZG-CLASS-ID: mo00 Received: from mail-qk0-f172.google.com ([209.85.220.172]) by smtp.strato.de (RZmta 39.12 AUTH) with ESMTPSA id w0a206t0VBrnBax (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp384r1 with 384 ECDH bits, eq. 7680 bits RSA)) (Client did not present a certificate) for ; Tue, 31 Jan 2017 12:53:49 +0100 (CET) Received: by mail-qk0-f172.google.com with SMTP id 11so160588665qkl.3 for ; Tue, 31 Jan 2017 03:53:49 -0800 (PST) X-Gm-Message-State: AIkVDXI3pQAv4oQrbW6Y4kIx+rYmdDzH/FTBR9+Eyty+u0h33xfv3Pr5abgPi5GwA4P38TJ7u/FusWCkxj8g4g== X-Received: by 10.55.120.3 with SMTP id t3mr26043027qkc.0.1485863629208; Tue, 31 Jan 2017 03:53:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.144.132 with HTTP; Tue, 31 Jan 2017 03:53:48 -0800 (PST) In-Reply-To: References: <3F428CA4-8211-44E6-9B60-62ADB47934B3@koalephant.com> <642a72cd-e322-0b22-452f-dfbd521aee02@php.net> Date: Tue, 31 Jan 2017 12:53:48 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Bob Weinand Cc: Michael Wallner , Andrea Faulds , Stephen Reay , PHP internals Content-Type: multipart/alternative; boundary=94eb2c065d98cdccd905476295d8 Subject: Re: [PHP-DEV] [RFC][Discuss] Arrow Functions From: me@kelunik.com (Niklas Keller) --94eb2c065d98cdccd905476295d8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2017-01-31 12:14 GMT+01:00 Bob Weinand : > Hey, > > > Am 31.01.2017 um 11:23 schrieb Michael Wallner : > > > > On 31/01/17 05:53, Stephen Reay wrote: > >> Hi Andrea, All, > >> > >>> On 31 Jan 2017, at 08:12, Andrea Faulds wrote: > >>> > >>> Is it necessary to introduce a new keyword, fn? > >>> > >>> I think you'd get a similar benefit from: > >>> > >>> function($x) =3D> $arr[$x] > >>> > >>> Likewise, is it necessary to restrict auto-capture to the =3D> > >>> syntax? Couldn't we allow the following? > >>> > >>> function ($x) { > >>> return $arr[$x]; > >>> } > >>> > >> > >> I agree that the `fn` keyword isn=E2=80=99t really necessary. I=E2=80= =99ve never > >> quite understood how arrow functions with implied returns etc are > >> supposed to make for *more* readable code, but if they=E2=80=99re goin= g to be > >> part of the language please at least keep some consistency with > >> regular closures. > > > > Yes, I also think that keeping the function keyword would be better. > > > >> > >> In the case that regular closures got auto-capture, would a > >> `use($foo, $bar, $baz)` segment on a closure still be honoured (i.e. > >> disable auto-capture), and would it have any impact (positive or > >> negative) on performance/memory usage? After several years of JS > >> closure =E2=80=98fun=E2=80=99 I kind of like that with PHP you only in= herit the > >> variables you explicitly `use()` in closures. > > > > Wouldn't there be just too many existing closures, which do not use > > `use` but (maybe) expect a clean scope? > > > The RFC is exclusively proposing single-expression short Closures. > We do NOT want multi-statement short Closures; it is a *feature* that > generic Closures need an "use ($foo, $bar)". > This vastly improves readability and debuggability - it basically tells > you whether the variables inside the code are imported or not. As Stephen > Reay notes: > >> After several years of JS > >> closure =E2=80=98fun=E2=80=99 I kind of like that with PHP you only in= herit the > >> variables you explicitly `use()` in closures. > > > So, auto-import for generic Closures definitely isn't an option. > Just on short, single-line Closures there is no benefit to "use ()", as > EVERY variable used in the short Closure is supposed to be an imported > variable. There is no point in forcing the user to distinguish between > imported and local variable here. > > Also, using "fn" in favor of "function" has the advantage of less clutter > in one line. Compare > > array_map(fn($x) =3D> $x + 1) > > to > > array_map(function($x) =3D> $x + 1) > "function" is actually easier to recognize than "fn" for me. Humans read things by the first and last letter + contained letters, they don't read each letter separately, so a little bit longer keyword doesn't hurt readability, it might be even improved, because "function" is a keyword people are used to. And it comes with the benefit of no BC break, because "function" is already a keyword. Also updating array_map(function ($x) =3D> 2 * $x, [...]); to array_map(function ($x) use (...) { ... }, [...]); is a little bit easier then, just in case you need an additional statement there. > The syntactical construction is already pretty clearly showing what's > going on. The "function" keyword itself is already larger than the whole > body. Now we're counting chars again instead of keeping the focus on actual readability? > It distracts while reading the actual code. > I disagree here, as mentioned above. > Additionally, using "fn" is optically highlighting the fact that it's a > short-Closure with auto-import and not a normal Closure with explicit > import. > > Thanks, > Bob I think I prefer "function" instead of "fn", but I can also live with "fn". Regards, Niklas --94eb2c065d98cdccd905476295d8--