Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88074 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58794 invoked from network); 7 Sep 2015 05:33:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2015 05:33:06 -0000 Authentication-Results: pb1.pair.com smtp.mail=pajousek@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pajousek@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.169 as permitted sender) X-PHP-List-Original-Sender: pajousek@gmail.com X-Host-Fingerprint: 209.85.213.169 mail-ig0-f169.google.com Received: from [209.85.213.169] ([209.85.213.169:37820] helo=mail-ig0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/52-40368-F812DE55 for ; Mon, 07 Sep 2015 01:33:05 -0400 Received: by igbni9 with SMTP id ni9so50604749igb.0 for ; Sun, 06 Sep 2015 22:33:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=JcAM8P8vxZuPau7ia6gwT2gB5EQHmIxrcftM4u3Nzfs=; b=SsGJ+dCAwUHd6bzV//jt9zWEzPGs2ihL/rZq9RaumdJD3ndacL0JqvXsbBtQ/0KtY5 qO+zzX1NzV+iEX2vgg5gWHtytDoJfiB5Amsfg4f1H3agrQKa0JNySJte3G8atHpvqgiH gCSwo7Ri9Dn1MjrhqHTqQ1n0Qjq8dOxxQUxhufrB1YfRvqIli+CyoojWogz9+NFZO4Lf f9lhRnYbU2qakTT2zjL16iJx2q2F5Py9yfRDD8D8L7069mKrLKufLUwE0LmmR2crXcA5 6L6jN5qWYaaHGYefmwLgf058YFF4ID8v1nYoqzv6hjaPuefWBikaRdfRuLl9/yTv7wyh E6CA== MIME-Version: 1.0 X-Received: by 10.50.43.202 with SMTP id y10mr3434078igl.86.1441603981448; Sun, 06 Sep 2015 22:33:01 -0700 (PDT) Received: by 10.107.24.194 with HTTP; Sun, 6 Sep 2015 22:33:01 -0700 (PDT) In-Reply-To: <61.90.26858.306BCE55@pb1.pair.com> References: <61.90.26858.306BCE55@pb1.pair.com> Date: Mon, 7 Sep 2015 07:33:01 +0200 Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: [RFC] [Discussion] Short Closures From: pajousek@gmail.com (=?UTF-8?Q?Pavel_Kou=C5=99il?=) On Sun, Sep 6, 2015 at 11:54 PM, Andrea Faulds wrote: > Hi Bob, > > This has probably already come up, but I'd like to weigh in on the symbol > choice. > > On the subject of syntax, ~> (let's call it the squiggle arrow) seems lik= e a > very poor choice compared to =3D=3D> (let's call it Hack's arrow). > > I think it's been mentioned that =3D=3D>, Hack's arrow, was thought to be= likely > to be confused with =3D>, the key/value separator in array() and foreach(= ). > But I'd argue this is actually rather unlikely, for two reasons. > > The first of these is that =3D=3D> is a whole column wider. So, if there'= s a > smudge on the screen or something, you could still clearly distinguish = =3D=3D> > from =3D>. They're visually distinct, much like =3D, =3D=3D and =3D=3D=3D= are, which I'm > sure any PHP programmer can tell apart. > > Second, =3D> is only used in very limited contexts. You can't use =3D> in= a > normal expression or statement. You can't mistake ($t =3D=3D> $f =3D=3D> = $t) for ($t > =3D> $f =3D> $t) for long, because the latter would never be a valid expr= ession. > And in the contexts where =3D> does work, it's unlikely you'd be using a > closure =E2=80=93 at least, I can't think of a case where you'd want to c= reate a > numeric array of closures using a literal. > > For those two reasons, I don't agree that confusing =3D=3D> with =3D> wou= ld be a > big problem. > > Now ~>, the squiggle arrow, was supposedly chosen to reduce the likelihoo= d > of confusion. However, I would argue that it is actually *more* likely to > cause confusion. In this case the potential confusion would be with ->, t= he > object property dereference operator. I have two reasons for why the two > operators would be confused, and they're the respective inverses of the > reasons why =3D> and =3D=3D> wouldn't. > > First, ~> visually takes up the same amount of space as ->, so if you hav= e a > small character size, a blurry or low-resolution screen, or poor eyesight= , > there's nothing aside from the very slight curvature (and maybe syntax > highlighting, which does not yet exist) to distinguish ~> from ->. > > Second, ->, the object property dereference operator, is used in a wide > range of contexts. It's a valid expression (and thus statement), and so > would crop up in many places where ~>, the squiggle arrow, also would. A > realistic example of this is the Church Booleans, an encoding of the bool= ean > values "true" and "false" in the lambda calculus: "true" is a function th= at > takes two arguments and returns the first, and "false" is a function that > takes two arguments and returns the second. The "true" function would be > written, using squiggle arrows, as ($a ~> $b ~> $a). Now, if you squint, = can > you tell that apart from ($a ~> $b -> $a)? Did you even notice the > difference in that second expression? (The second squiggle arrow become a > dereference operator.) I wouldn't be surprised if you didn't. And the > difference wouldn't always be immediately obvious from context. Here, the > unusual spacing might give it away (a variable property access would usua= lly > be $b->$a), but not everyone is going to put spaces around their squiggle > arrows. > > For those two reasons alone, I think ~> is a poor choice. And that's with= out > the ugliness issue: in some fonts, particularly Japanese ones, ~ is rende= red > at the top of the character box, like an overline. In such a font, ~> wil= l > not look like an arrow. > > You did mention that the HHVM team might find things easier if you chose = ~> > instead of =3D=3D>, given Hack already has =3D=3D>. Surely, though, that = only > matters if =3D=3D> has different semantics in PHP and Hack, yet this prop= osal > matches Hack's implementation exactly, so far as I can tell. Also, it wou= ld > be nice if PHP and Hack don't diverge when implementing the same features= , > unless there's a particularly good reason... it's not very kind to people > who use both languages. > > So, to conclude, I would urge you to change the RFC to use =3D=3D> instea= d of > ~>. > > Thanks. > > -- > Andrea Faulds > http://ajf.me/ > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > Hello, these are all good points. Also, I realized it's definitely harder to write ~ than =3D. On my keyboard layout (Czech Qwerty) I have to do "right alt + shift + (key above Tab)". I'm not sure how it is with other non-US keyboard layouts, but it might be worth exploring before deciding on a symbol; or maybe there's a possibility that my keyboard layout is just an anomaly and you can write ~ on most keyboard layouts with a single key (or double). Regards PK