Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99697 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91875 invoked from network); 3 Jul 2017 02:49:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jul 2017 02:49:47 -0000 Authentication-Results: pb1.pair.com header.from=andreas@dqxtech.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=andreas@dqxtech.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dqxtech.net from 209.85.223.171 cause and error) X-PHP-List-Original-Sender: andreas@dqxtech.net X-Host-Fingerprint: 209.85.223.171 mail-io0-f171.google.com Received: from [209.85.223.171] ([209.85.223.171:35507] helo=mail-io0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/37-60825-BC0B9595 for ; Sun, 02 Jul 2017 22:49:47 -0400 Received: by mail-io0-f171.google.com with SMTP id h134so48446769iof.2 for ; Sun, 02 Jul 2017 19:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=+benYIcoWxlK1wN532xUv9opCUMyohKZWTVZvBwH5Dg=; b=Li5Ia8AccF3NfhdLIxOaqwE+k+IZEXumeJDV1ek297/VZbOdEpGpswLNs+C4SALKDG Cs8u+aI6tQjDSQojtwAx0gvOU+ytFxHLrTxLBFwJVNBYjG0fYASAEF2uDO5k33RRuwWb 49ojm9opPtyphPoZa0ydybyQmGnwzNjGWkozugmTkrPv41Q2vqFt642QJRb0nFqG30mO W+juYWezkpl2btwy+NEChEr1krkqEajtwphzigv7LQHUa9jUFOBlXWr7RwO3wLFOe7C7 c/upeWLhS0KDWTkhaNF2FEMTCEFnx0vhDh3JMbaKrciWvJREMjV6fCV4hSIoodJtNPDr V5Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=+benYIcoWxlK1wN532xUv9opCUMyohKZWTVZvBwH5Dg=; b=GCCiniDZPJrLGfQBcqNulJTSvVr1EBU/bhiQUXxLwUetbCehzQxTJda//d48oJn1RV WdwklBM7yU+uuDPc2iP4m9Ch2DtYuIHBmW5P7YD3RDiRT2fgaTAsW6IgWKvNRZCaS0Wq W0PEA8Bv8sU2Ho/U1XxDEp7SoU/jaO1OdAxaa2IiLSGU/O9/fg3LK5Yfx427/qoqCdhB +iG8zzu+kRYR2PyJpkQdJmiYN5qdvZ9vLtdTRfCyOQpTOsO67W0InDL2G4u9EpzJfcG5 JTWT0NvG31Q1w8MNnR8Qa0pOQVZalmluUiEoQ7qW5VeWXEk+ajZtPkRaprlZ+xCJzYAq jVSg== X-Gm-Message-State: AIVw110JaB0QO8EPqV6zt41xxUEm7Vm2CPqg1K5EcZnZGrguNhUQv2P+ b+Du1U489V1HAbwxxGI= X-Received: by 10.107.160.148 with SMTP id j142mr13449751ioe.78.1499050184339; Sun, 02 Jul 2017 19:49:44 -0700 (PDT) Received: from mail-it0-f54.google.com (mail-it0-f54.google.com. [209.85.214.54]) by smtp.googlemail.com with ESMTPSA id s135sm9564618ita.2.2017.07.02.19.49.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Jul 2017 19:49:43 -0700 (PDT) Received: by mail-it0-f54.google.com with SMTP id m68so81914929ith.1 for ; Sun, 02 Jul 2017 19:49:43 -0700 (PDT) X-Received: by 10.36.40.145 with SMTP id h139mr488906ith.84.1499050183534; Sun, 02 Jul 2017 19:49:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.246.71 with HTTP; Sun, 2 Jul 2017 19:49:23 -0700 (PDT) In-Reply-To: References: Date: Mon, 3 Jul 2017 04:49:23 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] "Reader" as alternative to Iterator From: andreas@dqxtech.net (Andreas Hennings) Well, on a current project I made an attempt to write different adapters in userland. I finally decided that the clutter is not worth. So for this project I wrote everything as "readers", and not as iterators. With a native solution, one could do this: function generate() { yield 'a'; yield 'b'; yield 'c'; } $it = generate(); while (FALSE !== $v = $it->read()) { print $v . "\n"; } With a userland adapter, the code would read like this: function generate() { yield 'a'; yield 'b'; yield 'c'; } $it = generate(); // This is the added line. $reader = new IteratorReaderAdapter($it); while (FALSE !== $v = $reader->read()) { print $v . "\n"; } This does add clutter and performance overhead. In this example I'd say this is acceptable / survivable. In the project I was working on, I have multiple layers of "readers": - One layer to read raw data from a CSV file. - One layer to re-key the rows by column labels. - One layer to turn each row into an object, with structured properties instead of just string cells. With the "reader" approach, for each layer I would have one "reader provider" class and one "reader" class per layer. (In fact I have much more, but let's keep it simple) Generator syntax would allow to have only one class per layer. But with the additional adapter, we again increase the number of classes. (I wanted dedicated reader classes for different return types, e.g. one "RowReader", one "AssocReader", one "ObjectReader". So here I would need one adapter class per type. But let's focus on the simple case, where you can use the same reader class.) In addition to more classes and more function calls (performance), the adapters also make stack traces heavier to look at. Overall, for this project, I decided that it was not worth it. The main purpose of the generator syntax is to simplify the code. The need for userland adapters defeated this purpose. Native readers would have made generators worthwhile for my use case. The idea of "dedicated reader types" e.g. Reader could be added to "Open questions"..