Re: [RFC] Pipe Operator
| From: | François Laupretre | Date: | Thu, 12 May 2016 18:52:03 +0000 |
| Subject: | Re: [RFC] Pipe Operator | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93287@lists.php.net to get a copy of this message | ||
Hi Sara,
Le 12/05/2016 à 19:02, Sara Golemon a écrit :
On Thu, May 12, 2016 at 5:48 AM, Zeev Suraski <zeev@zend.com> wrote:Currently, the proposal accepts any expression between '|>' operators, which requires the '$$' placeholder (as '|> $$ + 2 |>' would be valid). If we restrict usage to function calls, we can quite easily get rid of the $$ by associating to each function the position where the lhs must be inserted when used as a 'piped function call'. This position would be 0 (first arg) for most existing functions and 2, for instance, for str_replace(). Getting rid of the $$ would resolve most issues about parameter order in the existing library, which is probably the biggest PHP sadness. My question, before I write a detailed proposal for this, is : do you want to keep the possiblility to use *any* expression between pipe operators, or would it be acceptable to restrict this to function calls? Note that it would also disambiguate 'piped assignments' like '|> $var |>' (assigning to an intermediate or final variable). Regards FrançoisWhether it's $$ or !# or $0 or any other random symbol doesn't really matter.Agreed.Here we have a completely optional syntactic sugar, that's not nearly as widely useful as OOP or namespaces.Very few things will be as widely useful as OOP or namespaces, so that comparison is a bit of a red herring. This construct is useful anywhere function call nesting pushes you past a readability threshold. That's not as ubiquitous as OOP as a whole, but it's pretty widespread. As widespread as fluent call chaining, in fact.The question is whether the added complexity of a new operator, a new symbol and the new semantics around them both are worth the benefit of introducing them.Agreed. There's a cost to every new token and parser rule on the compiler side, and there's a cognitive overhead on the script maintainer side as well. It seems we only disagree in the flexibility provided by better syntax and the ease of using google, stack-overflow, and php.net/manual.IMHO it's not.And I'll expect you to vote accordingly. No hard feelings. :) -Sara