Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62242 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86458 invoked from network); 18 Aug 2012 14:12:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Aug 2012 14:12:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lsces.co.uk from 217.147.176.204 cause and error) X-PHP-List-Original-Sender: lester@lsces.co.uk X-Host-Fingerprint: 217.147.176.204 mail4.serversure.net Linux 2.6 Received: from [217.147.176.204] ([217.147.176.204:52929] helo=mail4.serversure.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 78/B7-31572-3D2AF205 for ; Sat, 18 Aug 2012 10:12:36 -0400 Received: (qmail 15671 invoked by uid 89); 18 Aug 2012 14:12:32 -0000 Received: from unknown (HELO mail.lsces.co.uk) (127.0.0.1) by mail4.serversure.net with SMTP; 18 Aug 2012 14:12:32 -0000 Received: from 212.183.128.50 (SquirrelMail authenticated user lester@lsces.co.uk) by mail.lsces.co.uk with HTTP; Sat, 18 Aug 2012 15:12:32 +0100 (BST) Message-ID: <13989.212.183.128.50.1345299152.squirrel@mail.lsces.co.uk> In-Reply-To: References: Date: Sat, 18 Aug 2012 15:12:32 +0100 (BST) To: internals@lists.php.net User-Agent: SquirrelMail/1.4.9a-1.3.6 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Subject: Re: [PHP-DEV] [RFC] Generators From: lester@lsces.co.uk > On Sat, 11 Aug 2012, Nikita Popov wrote: > >> Hi internals! >> >> I think there already was a lot of discussion on the generators, so >> it's time to move to the next step. I'd like to vote on the feature in >> two weeks, so this the "announce[ment] on internals@, by the author, >> with the intention of voting on it". >> >> https://wiki.php.net/rfc/generators >> >> If you have any further feedback, now would be a good time to raise >> it. If there is something you previously posted, but which I didn't >> yet address, please let me know. There were around 150 mails and I >> sure missed some of them. > > I've some comments how that I've read the RFC: > >> Recognition of generator functions >> >> 1. Any function which contains a yield statement is automatically a >> generator function. >> >> 2. The initial implementation required that generator functions are >> marked with an asterix modifier (function*). This method has the >> advantage that generators are more explicit and also allows for >> yield-less coroutines. >> >> The automatic detection was chosen over the asterix modifier for the >> following reasons: > > I am against this. This is even more magic in PHP. Is it really that > difficult to have to mark the function with a different keyword, such as > "generator": 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 ... >> generator function getLinesFromFile($fileName) { >> if (!$fileHandle = fopen($fileName, 'r')) { >> return; >> } > >> There is an existing generator implementation in HipHop PHP, which >> uses automatic-detection. Using the asterix modifier would break >> compatibility. > > This should not be a concern, sure, it's annoying for the hiphop > developers but they chose to copy and then *chance* the PHP language for > their own effect. > >> yield: Yields the value null with an auto-incrementing integer key. > What is the usecase for this? I can see some interesting porting problems with this ... one of the stock changes when moving from a MySQL only setup to support other databases is to remove the auto-increment magic, and replace it with proper sequence code prior to inserting. I can see translating a 'MySQL' geared generator into a more general one as being impossible if some tricks like this are used. (Out in an exhibition hall this weekend so not able to follow properly)