Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62243 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88308 invoked from network); 18 Aug 2012 14:28:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Aug 2012 14:28:27 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.212.42 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:54596] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EA/18-31572-986AF205 for ; Sat, 18 Aug 2012 10:28:26 -0400 Received: by vbbfs19 with SMTP id fs19so4775549vbb.29 for ; Sat, 18 Aug 2012 07:28:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=2Jr2uNhraAZQ3CBOR8DJ6vC/0gBPPCTkrH95sr5FoFM=; b=jpiGwDEYufKhLTG9nML8m2XxXIVW74FPscuI/uO+/WVmHjdBEYVpX/z6xW3mRhdMkY ite8u8CxrfyIMzvRWfp6D7NdEzu3S5UQuUPsvOHAtb5FiI7FmgtfPK2q2/t2IMpW/KM+ U172gGE8nOWjyo699m0jeBkIIJ8puha51vb3HYUIPHgeDIfsW+YFsRrLNhcfhXjYtUQI br+2C2U5glLp9YXJu3D5ZgrzFRTYsNn1vmXHvkwjzDAaG+tOB94JGh32kLBpKeH/wsX+ EE8uTVfxiTZqsZIIEPFcs26gKybRf2pdSBFaFPye/hLTUUzkOEMBcLlpUfJU7GCXcNzl adIQ== Received: by 10.220.152.134 with SMTP id g6mr5553537vcw.10.1345300103395; Sat, 18 Aug 2012 07:28:23 -0700 (PDT) Received: from [192.168.2.140] (CPE00131063dcac-CM0011aec551ea.cpe.net.cable.rogers.com. [174.113.209.222]) by mx.google.com with ESMTPS id us1sm1836481vec.9.2012.08.18.07.28.21 (version=SSLv3 cipher=OTHER); Sat, 18 Aug 2012 07:28:22 -0700 (PDT) Message-ID: <502FA684.6060204@lerdorf.com> Date: Sat, 18 Aug 2012 10:28:20 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: lester@lsces.co.uk CC: internals@lists.php.net References: <13989.212.183.128.50.1345299152.squirrel@mail.lsces.co.uk> In-Reply-To: <13989.212.183.128.50.1345299152.squirrel@mail.lsces.co.uk> X-Enigmail-Version: 1.5a1pre Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQlk5/UzSFIej5LafP5hU2OheX6RBpsr7DnLkVGO9HOk5uBDavkyeeCvyPfVEVINcXU3srQA Subject: Re: [PHP-DEV] [RFC] Generators From: rasmus@lerdorf.com (Rasmus Lerdorf) On 08/18/2012 10:12 AM, lester@lsces.co.uk wrote: > Since this is yet another area where 'one does not have to use it if one > does not want to' ... FLAGGING to the other users that a function is a > 'special one' rather than just a normal function with a generator function > seems to me just a necessity? HAVING to work through a functions code > simply to see if it contains a 'yeild' so as to understand that it's not > going to give a normal return seems insane? Alright the function can be > properly documented with a docblock, but if it isn't ... I don't see how that is any different from having to look through a function to see if it is a void function or if it returns something, and if so, what it returns. Or checking to see if it outputs something. PHP is very dynamic. A function can be both void and non-void at the same time. It can return mixed types and do pretty much anything you can imagine. I don't really see what the generator keyword achieves. What happens if I have a function that I mark as a generator but then I don't put a yield in it? Is that a compile-level error? That might work, but then what if I put a yield in it but the logic of the function never gets to it: if(cond) return [1,2,3]; else if(other_cond) yield $val; else return; There is no way to know at compile-time whether the yield will ever be reached. To me it seems odd to have a generator keyword that cannot be enforced and doesn't mean anything other than stating a developer's intent. Whether the developer actually carried through and implemented the intended generator can only be verified by reading the code. This smells much more like a source comment to me. If we were going to go with a generator keyword, then I think the feature needs to be completely re-thought. I would suggest dropping the yield keyword entirely and having return be equivalent to a yield if the function is marked as a generator. Then the keyword actually does something. -Rasmus