Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94489 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58622 invoked from network); 12 Jul 2016 13:54:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jul 2016 13:54:58 -0000 Authentication-Results: pb1.pair.com header.from=dmgx.michael@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmgx.michael@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.41 as permitted sender) X-PHP-List-Original-Sender: dmgx.michael@gmail.com X-Host-Fingerprint: 209.85.218.41 mail-oi0-f41.google.com Received: from [209.85.218.41] ([209.85.218.41:33951] helo=mail-oi0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2E/B9-17655-0B6F4875 for ; Tue, 12 Jul 2016 09:54:57 -0400 Received: by mail-oi0-f41.google.com with SMTP id s66so23277017oif.1 for ; Tue, 12 Jul 2016 06:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to; bh=pRCxJTN6vOb1ZrS8735rCEwY1LfTb7vOaLZET7AheKw=; b=0yB3sz5y1NIdNaQI6kvN9tJ4IjlTMhy6nnHT3EGSJuKBYNKlKcZ7BBAaWonyY4tAS0 oPdb21lk+YMs2gRpmJahbOnAZj8c6411TTS/VXebr1FsywWWmF65TX1Q2ag/HYjGsrqx PwaxKg1ZXUKAIfmAT08yHOlYjKwW1iV2NxqSJ71ywoSsO3XRN6WdRBlpwc4xsX447/+H zbk7LqliQfUngFQAk7GgCy+pGDTrQAL4Y0/Sn+BQ4xZNxOtcMBdaE/nC0z/NyZyZIK01 JuwegLAMhl/lSIZuT+H2DF9GJzMSftJRvulx9VlqfuKR/a9Y1TJL5UVvNconbPC32yBB Fg+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to; bh=pRCxJTN6vOb1ZrS8735rCEwY1LfTb7vOaLZET7AheKw=; b=BprLkRGNRTcTjZJvj/ZUce4hQ5m1XH8G1921CMD8cBYKlyRRiPtpRXvvh6EXU69p7L vBljVB7s+fssI37WeV8aSVok+J/7msowipFF0SBzFXvxtGQ9lWlYgtqjdeJeVOTv49tt rRqBT9xqZ1kbZrpT2dSX8hTASStqeR/hTZDDFtOxwqaMkmQnboXhl0DsD0YK+DE42eeH ypL6XtX7tMWCnEp6L+CXPwz1HqcM5gKz6OvyKMp2KKRqpwlW6MJ76Z4CxdUOdc1m4CvQ IFLUEtaBZtdR3k8ozUzmYtU2YDqnBAhukW9+iQzzZVhb7hYtwqjlndkuGZrUUXU0egkB rQDg== X-Gm-Message-State: ALyK8tJ18ZS0HgET+1iwPiVUnPaO9euAX+0EX5h4evqgaIvsawDS1Z3aT71Xgt8mxn/gMMbkBSeEqUEqEyK8MQ== X-Received: by 10.157.11.65 with SMTP id p1mr1350822otd.169.1468331694118; Tue, 12 Jul 2016 06:54:54 -0700 (PDT) MIME-Version: 1.0 Sender: dmgx.michael@gmail.com Received: by 10.182.216.133 with HTTP; Tue, 12 Jul 2016 06:54:53 -0700 (PDT) Date: Tue, 12 Jul 2016 09:54:53 -0400 X-Google-Sender-Auth: -nKcDkjKKxbzd5LUlW3XhhBBzVk Message-ID: To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= , PHP Internals List Content-Type: multipart/alternative; boundary=001a1141ca7c0a5e920537709d2c Subject: Re: [PHP-DEV] Cascade Operator (was Re: [PHP-DEV] Proposal for php7 class method return) From: tendoaki@gmail.com (Michael Morris) --001a1141ca7c0a5e920537709d2c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Jul 11, 2016 at 1:55 PM, Micha=C5=82 Brzuchalski < michal.brzuchalski@gmail.com> wrote: > 11 lip 2016 18:31 "Rasmus Schultz" napisa=C5=82(a): > > > > > what's the actual added value of this sort of operator? > > > > The only direct value to the language is brevity - mere convenience. > > > > But I think the biggest indirectly added value, is that this will > > discourage people from the chainable methods anti-pattern - so this > > has value to the community; those who write chainable methods can > > stop, and those who want chainable methods can get a wider choice of > > libraries that were previously too verbose in use for their taste. > > > > > For this sort of chaining I'd propose, in addition to the cascade > operator, > > > the chain operator. This would work like the cascade operator except > that > > > the return of the function is implicitly the first parameter of the > next > > > argument in the chain > > > > I don't like this idea, at all - I think we should aim for something > > consistent with other languages. Per the Dart spec: > > > > > A cascaded method invocation expression of the form e..suffix is > equivalent to the expression (t){t.suffix; return t;}(e). > > > > In other words, the expression always evaluates as the object, which > > is fine for most cases, e.g. for everything you're doing with > > chainable methods today - which can't actually return any values, > > since they return $this. Note that something like PSR-7's HTTP > > immutable models are actually factory methods, e.g. use-cases not > > applicable to the cascade operator. > > > > The other marginal use case perhaps is cases where a builder of some > > sort ends with a call to a factory method - this can be done without > > adding a second operator, by using parens in a similar fashion to Dart > > and others, e.g.: > > > > $object =3D ($builder > > ->>setFoo(1) > > ->>setBar(2) > > ->>setBaz(3) > > )->build(); > > > > Or obviously: > > > > $builder > > ->>setFoo(1) > > ->>setBar(2) > > ->>setBaz(3); > > > > $object =3D $builder->build(); > > > > Regarding syntax - I feel the natural choice, e.g. similar to "." vs > > "..", would be a longer arrow --> but that's ambiguous. (decrement > > operator, greater than operator) > > > > The proposed |> operator looks horrible and is very awkward to type, > > at least on both American and Danish keyboard - I use both. (it reads > > like "or greater than" in my mind, so much so that glancing over > > Sara's proposal earlier, I didn't even understand what it was.) > > > > Would something like ->> be ambiguous as well? That's fairly close too > > - a double-headed arrow, not unlike the double dots of other > > languages... > > > > IMHO double-headed arrow looks pretty nice and whole idea is great. Very > big +1 for this feature > > > Agreed, but what about static methods? Triple colon perhaps? A::setFoo(1) :::setBar(2) :::setBaz(3); And I do agree that the double period is cleaner, but the bus left the station a very long time ago (PHP 3 at least) by making . the connotation operator. Or at least I think so. If the parser could deal with it double period would be best because it could apply to both contexts. $object->setFoo(1) ..setBar(2) ..setBaz(3); A_Class::setFoo(1) ..setBar(2) ..setBaz(3); But again, I don't know how feasible the above is since I know next to nothing about internals. --001a1141ca7c0a5e920537709d2c--