Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92970 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86042 invoked from network); 30 Apr 2016 06:49:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Apr 2016 06:49:56 -0000 Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.49 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.215.49 mail-lf0-f49.google.com Received: from [209.85.215.49] ([209.85.215.49:33315] helo=mail-lf0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 36/73-58459-29554275 for ; Sat, 30 Apr 2016 02:49:54 -0400 Received: by mail-lf0-f49.google.com with SMTP id y84so139921707lfc.0 for ; Fri, 29 Apr 2016 23:49:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=cMVWttSOAPbFT8awkU9WJBmipiJQM5/Zr99oVh8ItXg=; b=0Zzt9WGq8MTHMiymcnzz2cXfnPxPgKHXzOX6/H9ZUJ2/c7x9uLLXcFK8DYa+hTb3I4 ndDpdIJApNG5gLdw9NBGJLHaSrCCCZ6Hom2qM3hVJ/rc9VntV/fHt+d1T8A1D56menwo nYED/wRg9GljQWtAdidCS2LSykdE2HnUWfOVI90EAxgik+/3muDK3Q1PAKo8sRr/kNWI h1NcsxKO7INxZUPNJ0aNVlPiVVrJvdZfJYkurOEam4zgBf/UVw/sK2b33Kk4CuWHPj3n G94pPV1vQvkfQPJ2znddizOOsNQKk4BJlsIeGTjjNIgGdYJdro274ZEV/qDwV+JUONqq rfbA== 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; bh=cMVWttSOAPbFT8awkU9WJBmipiJQM5/Zr99oVh8ItXg=; b=KCtFkRq/o+g2ekfGWRIQlMXRFEY/lmI8ct3EEwmDsv4zH84dIDus0P5vwfaZWrDjCV VERPMlE6OAYan85x/4nYonSD/QBY7E7S5ueojSTVAuoDiwFa4zP+xlUMPE/D438db+SM 1Jan8kezPtlFdcYJbkXwq6qw1F2NPTT7WSm6hTDrIGIOL837Iq6xTSzmL7D9mAcSIpoi 2hdB413Do9lzVjGBDyARNIkN/IOJfclWnXgLVguYCwR6cn8lSjAX8H5odDa9TxVJKST3 L7rzdhHpY5qxlW6I5G61B7CkBL4XV7kvZsuBk+WHtDhG8dryiuZTtQ/n7HggSMdmw1NA mQbA== X-Gm-Message-State: AOPr4FXF/F4SEHKcB104kzKewO3TgfBcG7LxbD2iAv5d0sONrSKdiEQqkso2he3ldDiONzNjno54lvLXDIMzHQ== X-Received: by 10.25.22.203 with SMTP id 72mr10596729lfw.84.1461998991376; Fri, 29 Apr 2016 23:49:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.126.67 with HTTP; Fri, 29 Apr 2016 23:49:31 -0700 (PDT) In-Reply-To: <8ea990da-1fe7-256c-4e08-0b30715c8e8a@gmail.com> References: <8ea990da-1fe7-256c-4e08-0b30715c8e8a@gmail.com> Date: Sat, 30 Apr 2016 08:49:31 +0200 Message-ID: To: Stanislav Malyshev Cc: Sara Golemon , PHP internals Content-Type: multipart/alternative; boundary=001a113f21da8b096d0531ae2a83 Subject: Re: [PHP-DEV] [RFC] Pipe Operator From: ocramius@gmail.com (Marco Pivetta) --001a113f21da8b096d0531ae2a83 Content-Type: text/plain; charset=UTF-8 I would say that this makes the entire functional approach: 1. more readable 2. easier to debug (woah, we can haz line numbers for failures!) Here's the pseudo-code for a typical request/response dispatch cycle: $request = getGlobals() |> parseRequest($$) |> buildPsr7Request($$); $response = loadConfig() |> buildDic($$) |> getApp($$) |> getRouter($app) |> getDispatcher($$, $request) |> dispatchBusinessLogic($$, $request, new Response()) |> renderResponse($$) |> buildPsr7Response($$) |> emit($$); Here's what it would look like with a separate approach (more business-oriented): buildRequest() // (basically the first part of the previous example here) |> validate($$) |> convertToCommand($$) |> execute($$) |> convertToViewModel($$) |> render($$) |> convertToHttpResponse($$) |> emit($$) I think this is much more readable/clear than any event-driven or procedural approach. We know exactly what is going on, we will get clear stack traces (this could need some fine-tuning of the current PR - I didn't try it out yet) and we will be able to introduce intermediate steps with ease. In addition to all that, this will ease reactive programming by a lot, as piping is a natural fit for streams and all abstractions around streams. The syntax is also already effective in F# (you can write very expressive and easy to understand code with it) and now also landed in Hack. I'd say +10 to this proposal :D Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 30 April 2016 at 02:19, Stanislav Malyshev wrote: > Hi! > > > This is one of my favorites out of HackLang. It's pure syntactic > > sugar, but it goes a long way towards improving readability. > > https://wiki.php.net/rfc/pipe-operator > > I think this takes the syntax too much towards Perl 6 direction. There > is a lot of fun in inventing cool signs like |> and making them do > nontrivial cool stuff. There's much less fun when you try to figure out > what such code is actually doing - and especially why it is not doing > what you thought it is doing. Brian Kernigan once said: > > "Everyone knows that debugging is twice as hard as writing a program in > the first place. So if you're as clever as you can be when you write it, > how will you ever debug it?" > > I think this applies not only to debugging, but also to reading programs > in general. If we are "as clever as we can be" with syntax, the program > becomes unreadable. > > For this feature specifically, I see nothing wrong with assigning > intermediate results to variables - moreover, I see an advantage to it > both in reading (you tell people what you expect to have happened in > this stage) and in debugging (you can actually *see* what happened and > *check* whether what you thought should be happening actually happened). > > If we could achieve the elegance of Unix pipes, I'd agree that it is > simple enough that we can see what is going on - but having it rely on > two magic things which are in different part of expression and > context-dependent ($$ means different things in different places) is too > much for me. > > -- > Stas Malyshev > smalyshev@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a113f21da8b096d0531ae2a83--