Re: [RFC] Pipe Operator
| From: | Yasuo Ohgaki | Date: | Mon, 09 May 2016 02:04:40 +0000 |
| Subject: | Re: [RFC] Pipe Operator | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93119@lists.php.net to get a copy of this message | ||
Hi,
I agree they are bad APIs.
Framework/library developer should provide better API
On Mon, May 9, 2016 at 1:08 AM, Fleshgrinder <php@fleshgrinder.com> wrote:
> $request = getGlobals()
> |> parseRequest($$)
> |> buildPsr7Request($$);
should be
require('some.lib');
$request = getRequest();
/* where getRequest() is
function getRequest() {
return getGlobals()
|> parseRequest($$)
|> buildPsr7Request($$);
}
*/
>
> $response = loadConfig()
> |> buildDic($$)
> |> getApp($$)
> |> getRouter($$)
> |> getDispatcher($$, $request)
> |> dispatchBusinessLogic($$, $request, new Response())
> |> renderResponse($$)
> |> buildPsr7Response($$)
> |> emit($$);
should be
require('some.lib');
$request = getRequest();
$response = getResponse($request);
/* where getResponse() is
function getRequest($request) {
return loadConfig()
|> buildDic($$)
|> getApp($$)
|> getRouter($$)
|> getDispatcher($$, $request)
|> dispatchBusinessLogic($$, $request, new Response())
|> renderResponse($$)
|> buildPsr7Response($$)
|> emit($$);
}
*/
> Suddenly I magically need to know how all of that procedural stuff goes
> together just to be able to keep it short while calling all of it?!?
>
> I hope you understand now why I am still asking for real world examples
> that are not based on endlessly bad code.
"|>" is just a building block for simpler coding. It could be used badly, but
it helps a lot. Procedural code could be much simpler and readable with "|>".
function getRequest() {
$config = loadConfig();
$dic = buildDic($config);
$app = getApp($dic);
$route = getRouter($app);
$dispatcher = getDispatcher($route, $request);
$businessLogic = dispatchBusinessLogic($dispatcher, $request, new
Response());
$resp = renderResponse($businessLogic);
$response = buildPsr7Response($resp);
return emit($response);
}
"|>" version is much easier to read and write.
I suppose most users will use it for easier coding, not for opposite.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net