On 21/07/2016 22:28, Sara Golemon wrote:
Are you picturing the return statement returning from the current
function? Or "returning" from the current pipe chain?

I think you mean the former, in which case I'd ask how that'd better/worse than:

return foo() |> bar($$);


I do indeed mean returning from the current function. I went into more detail (perhaps too much!) on the previous thread, but the basic premise is the pipe operator gives you code that reads left to right. Adding an element where you have to jump back to the beginning of the expression feels like it defeats that.

You picked an example with a very short pipeline, and the "return" is fairly obvious; but then "return bar(foo());" is not a great candidate for using the operator in the first place. Take a longer example:

return loadConfig()
   |> buildDic($$)
   |> getApp($$)
   |> getRouter($$)
   |> getDispatcher($$, $request)
   |> dispatchBusinessLogic($$, $request, new Response())
   |> renderResponse($$)
   |> buildPsr7Response($$)
   |> emit($$);


If you read through that pipeline, you get down to emit($$), and then have to scan back up to figure out where result of that is going to end up. Compare:

loadConfig()
   |> buildDic($$)
   |> getApp($$)
   |> getRouter($$)
   |> getDispatcher($$, $request)
   |> dispatchBusinessLogic($$, $request, new Response())
   |> renderResponse($$)
   |> buildPsr7Response($$)
   |> emit($$)
   |> return $$;


Here you can read through all the steps in order, right up to the last action, which is returning the resulting value.

Even the name "pipe" is suggesting that something goes in one end, and comes out the other, so having the output pop out next to the input just feels weird.

Regards,

--
Rowan Collins
[IMSoP]


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to