Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94466 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67123 invoked from network); 11 Jul 2016 15:15:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2016 15:15:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmgx.michael@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmgx.michael@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.44 as permitted sender) X-PHP-List-Original-Sender: dmgx.michael@gmail.com X-Host-Fingerprint: 209.85.218.44 mail-oi0-f44.google.com Received: from [209.85.218.44] ([209.85.218.44:33370] helo=mail-oi0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/58-22463-528B3875 for ; Mon, 11 Jul 2016 11:15:49 -0400 Received: by mail-oi0-f44.google.com with SMTP id u201so151789195oie.0 for ; Mon, 11 Jul 2016 08:15:48 -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=j5V7uW7h62eIsigOQuA/xQhnKh2Uyiy8UEQlGs3YciM=; b=ajL56HGcHvOMUIRgfXvEFak8mISFxP0RB+8/nKos/GM3zYwnfNX+Vk4TO2nvvrT6DD 1ey3NIEKuIAU1wUv9o3Sa1ptj3Z3cYaJbUvrL/3UWl46QJYWsyfz8Nu7qAm7KkA5ITG/ o6YwZPsZHUKZGwqXjLm69641RBoGIzVsTDKlJM4DkQW+gnOpwb/BHL1IUeLK+0CeXMyD otBXJO4e8nn/07HBz1YfQ+0TaZCbDZ/CsefAgrzWRTaWjMb7T/2lcQQvJv2qrt3jprS+ mV8362Mb8LXrF8YO6LmPErqrsq3UUPxOnyfEgzRD6j4Zw+Rk9MK+fQN8Wwbr5ierfprw O9AQ== 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=j5V7uW7h62eIsigOQuA/xQhnKh2Uyiy8UEQlGs3YciM=; b=bCPyiweBxjQr/eDk0+QDGXvGgR+A9m8XN8syVIXShLBp/rxLy7LcwuuKil614xgmfD Ws0ICn54q1FY65cuSIpbVBiof1oS5oIbAw7h4RFrwegpSWMgmBuXYT3sBwFRMuWIK8eI aMbMuwENhf+4JAGETgxp5jPGSTDy+y2MwaHqTyEhLOSZy53jRvnqQb8A4UG27RdKnVma Pirg7jmNYMYBwtU0KgZhsUPA9AR06dmjqzuGztLLz5YcQOlvkgn2oMd3BWqL0KJp0z7n HEbzyRhA8fSAIaCiqI4mIyxtuFxyRaEJOaXD58mlXNleVSS1ZqVVrH/PubOau2wDZJqz g+GQ== X-Gm-Message-State: ALyK8tLUFS2UBfm7k741tQQ9OaELZPIMZjMSx5jRePR7iHolUc9BsF14hKgSd3HFbf8GcBrkOaKIzTWhGReAOQ== X-Received: by 10.157.37.181 with SMTP id q50mr11400327ota.79.1468250144090; Mon, 11 Jul 2016 08:15:44 -0700 (PDT) MIME-Version: 1.0 Sender: dmgx.michael@gmail.com Received: by 10.182.216.133 with HTTP; Mon, 11 Jul 2016 08:15:43 -0700 (PDT) Date: Mon, 11 Jul 2016 11:15:43 -0400 X-Google-Sender-Auth: OzMQRWIFRyx71igHwZMSDcknAxQ Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary=001a11372fe447aed705375da039 Subject: [PHP-DEV] Cascade Operator (was Re: [PHP-DEV] Proposal for php7 class method return) From: tendoaki@gmail.com (Michael Morris) --001a11372fe447aed705375da039 Content-Type: text/plain; charset=UTF-8 On Sun, Jul 10, 2016 at 6:34 AM, Rasmus Schultz wrote: > > What you're really trying to accomplish is something like the ".." > operator found in some other languages - this is known as the "cascade > operator" in Dart, for example: > > > http://news.dartlang.org/2012/02/method-cascades-in-dart-posted-by-gilad.html > > There are several problems with method-chaining - the biggest problem, > as demonstrated by the cascade operator, is that this doesn't need to > be a problem you solve for every class; it can be done systemically > with a cascade operator, e.g. supported for every class, not just > those where you weave in this requirement. Also, method chaining is > inferior to a cascade operator, which would work not only for methods, > but for properties as well. More over, a cascade operator would work > for all existing libraries, whether the designer thought about > cascading use of various features or not. > > In short, this shouldn't and doesn't need to be a problem every > developer solves for each and every library - we can solve it for the > language instead. > > In other words, it seems you're trying to address a problem that > shouldn't exist in the first place, so that you can solve a recurring > problem you should not have to solve at all. > > I would be much more interested in seeing a proposal for a cascade > operator, which, in my opinion, addresses the real problem currently > driving developers to use method-chaining - I can only view that as an > unfortunate work-around. > > In my opinion, a cascade operator would move the language forward, > while the addition of a magical type-hint acting as sugar for "return > $this" merely solves a superficial problem - and propagates a bad > practice. > > This is a fascinating concept. There's a small gap to this implementation which I think can be improved on, but still fascinating. So we currently have -> for invocation of a method on an object. $a->setSomething('here')->setSomethingElse('there'); But for that to currently work setSomething must return $this. A cascade operator would avoid this. What about => ? $a->setSomething('here')=>setSomethingElse('there'); This alone is pretty cool, but what if you have a method that returns something you want to use as argument? The old prototype.js library. Consider the following class A { public function add( $a, $b) { return $a + b; } public function subtract( $a, $b) { return $a - $b; } } 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. Something like this? $a->add(1, 2):>subtract(3):>add(4); // return 4. As can be seen above, I'm unsure of what the static method syntax should be. --001a11372fe447aed705375da039--