Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94490 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73918 invoked from network); 12 Jul 2016 15:25:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jul 2016 15:25:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.213.41 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.213.41 mail-vk0-f41.google.com Received: from [209.85.213.41] ([209.85.213.41:34192] helo=mail-vk0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D0/AC-17655-DDB05875 for ; Tue, 12 Jul 2016 11:25:18 -0400 Received: by mail-vk0-f41.google.com with SMTP id o63so26608403vkg.1 for ; Tue, 12 Jul 2016 08:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=hXCdZUXdXfheqdgMeBGSvikPa5oH+K57ob4k29ntXfU=; b=1CrOPvNyandcYPynHK3BrBrrd7ZJZ1NzIZR+/w5jnAlhQ0FIBuIZUVb6DEM6J4RkAA YRR48pl8Q6XgVBiKRIn9MUq5Zx0XQjm5bYjcfeV828duoZhz/Ebv4DMx5q1nevfAYONe wP2hJ1KxzEY4UqT+NzEXTOF3E+BsyRyRJ8tOjdx3I3uzjmlHquqtXcsRoOdE0+5lPEQ3 /xJbmUTkK2oxZ4xD89L38SxoqA6EmFMhDGX+4SH0WksU1SpGT5Fe1zG5BcTz3O5S2Q92 9iDM36w5S0ZBsShS17gDyJVAF6aVD574B4wW1U/YBpAQFRhDJldn+a538S+l1DsdM6v8 Eh9A== 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-transfer-encoding; bh=hXCdZUXdXfheqdgMeBGSvikPa5oH+K57ob4k29ntXfU=; b=TkaWew/uqSIjbEVcf8yUGXAviYm2MMML9iBeOOEQ50XMlsgPLUxxmRDsL7eQP8bhud 7LnfqqZBwCsxrRTUFrqnti808O0X0kt9kp+1pdplUz09qpMVI8y8Qt5Lmt5+QF7aT2hv znxzRsanGcUQMeRrt+sCcGjQjLu7l2m8Z8R3mR5MYK+b1TSNx6C4GAPhdbkQllxpVBU8 0AZDIU88q9kSzqSdn/E+8DnOjoqY2JmFv1AyBnZaHw8meci+nfp7WIIyOjFvzN6sXlDh PDUFld9BmRWFpDBV3yXwyeawF8Tv40yG61BqjDgQhywC2SNilJy+xVn/eP9Zficzl7VI 3fXQ== X-Gm-Message-State: ALyK8tLhVAQNubyTSt3MYBouWSIRLqxjAmAD6Dg7vWHcRvGxSJsny4EMDEoHrNg5dQB0n/bP0O5EH8WKR72/qw== X-Received: by 10.159.35.112 with SMTP id 103mr1406101uae.55.1468337114695; Tue, 12 Jul 2016 08:25:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.105.9 with HTTP; Tue, 12 Jul 2016 08:25:13 -0700 (PDT) In-Reply-To: References: Date: Tue, 12 Jul 2016 17:25:13 +0200 Message-ID: To: Michael Morris Cc: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= , PHP Internals List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Cascade Operator (was Re: [PHP-DEV] Proposal for php7 class method return) From: rasmus@mindplay.dk (Rasmus Schultz) IMO, static methods have very little need for this feature - you rarely need to make repeated series of static calls and static property assignments. Let's not complicate this. On Tue, Jul 12, 2016 at 3:54 PM, Michael Morris wrote: > 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 doubl= e > 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.