Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61644 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45807 invoked from network); 23 Jul 2012 07:49:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jul 2012 07:49:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.213.42 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.213.42 mail-yw0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:43628] helo=mail-yw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/68-20357-FE10D005 for ; Mon, 23 Jul 2012 03:49:04 -0400 Received: by yhoo21 with SMTP id o21so5921445yho.29 for ; Mon, 23 Jul 2012 00:49:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:x-originating-ip:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=RBi0jNeKp1TDdPp5YRPED3j8JofVIx0u+FDYAzUusY8=; b=hGYA0wgLMMzl0wjeoGCSZ184DGLFb57RpGQs5WKXK4Qg+HzaJnYyhgieDbr7dyVaWy 4oup74OJINRgMjYpKDzxHv4mXkJK4fwsE5LfStnCKiM7bvQQOEd9MZr04LyRwX8X+/t8 hf+lpfwtludp7Rq2SvOCUQw3Red9ddODu07Vbue9x0UgIRV9j7Gd5kGd828c+j0HeBVM m/V2vkR47h7IYzxAN6q2j64P957t7k6UElzTa5wfXRuE+JgISvuzVGgXcZbM2hk0zxSr eSBASS6sRaI1BOr5pfgpAt4URU7FUo5hQGFcE4ZC5tjbNstr9etf0z2THlMUltX3TI8m EDbQ== MIME-Version: 1.0 Received: by 10.50.212.98 with SMTP id nj2mr13431108igc.35.1343029740776; Mon, 23 Jul 2012 00:49:00 -0700 (PDT) Sender: php@golemon.com Received: by 10.64.16.35 with HTTP; Mon, 23 Jul 2012 00:49:00 -0700 (PDT) X-Originating-IP: [67.164.28.199] In-Reply-To: References: Date: Mon, 23 Jul 2012 00:49:00 -0700 X-Google-Sender-Auth: ymEXEuHbAKf6nm6Z2QPEOKG7xwY Message-ID: To: Alex Aulbach Cc: Nikita Popov , Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary=14dae93404f19f2d3804c57a7ad2 X-Gm-Message-State: ALoCoQmPSSFyAAvLKsk7VrPGZU6MZLS4ZoyXFXIh0wcsBdtH2p+Uo9fiKBV9BnKKg0TqEGdo9m3p Subject: Re: [PHP-DEV] Re: Generators in PHP From: pollita@php.net (Sara Golemon) --14dae93404f19f2d3804c57a7ad2 Content-Type: text/plain; charset=ISO-8859-1 > > > My first thought was how could someone reading the code see, that it > is a generator? > Somewhat snarky answer: By documenting the code in the first place. Yeah, I know, we all inherit other people's code and the other person never writes comments. I don't think this is as big of a problem in practice, however. If you're looking at the function to understand what it does, you're certainly looking at statements like "return $foo;" already, right? Why would "yield $foo;" be any more stealthy? You posit that future engineer will have to spend hours understanding what generatorX does because it's 50+ lines long and original engineer isn't around anymore, but if the function is so complex, then future engineer is going to be spending hours whether or not it's a generator at all. Code like that is just bad code. The fact that it's a generator isn't the problem, nor is whether it's been explicitly flagged as such. Hm... not really satisfied with that. For me this is a little bit > unlogical, that just a simple function can return an object. > > So, how about implementing as a class? I mean: If it is returning a > class, why not implement it as class? > > Because that misses the entire point of generators as simplified iterators. What you suggest already exists, it's called: class foo implements Iterator { /* iterator funcs */ } Also, it doesn't allow for generators as class methods: class foo { function bar() { yield 1; } } Since this isn't Java, you can't really do: class foo { class bar implements generator { function __generator() { yield 2; } } } PS: I would like to see that yield goes hand in hand with the > iterator-stuff. > Curious if you could expand on that. Generators are iterators, so not sure what you're asking for. -Sara --14dae93404f19f2d3804c57a7ad2--