Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61790 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64363 invoked from network); 25 Jul 2012 20:08:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jul 2012 20:08:09 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.161.170 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.161.170 mail-gg0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:38467] helo=mail-gg0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/5F-19281-82250105 for ; Wed, 25 Jul 2012 16:08:09 -0400 Received: by ggnf2 with SMTP id f2so1380228ggn.29 for ; Wed, 25 Jul 2012 13:08:05 -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=fvuIpeg3Dg/EMi4jFtHIklBwIryTuJWYNM8AZ36ib4Y=; b=AuPQHxBpSNettrT88S5CKRW5o5lp/gqona9aRxbXnUM6a4mUoR2y/TVFLDbzNX9jnV 4QId1VUdaifQ1r6eFQiZkDU93rgAH6HQ6IV4k6ZK0fAGG/whFIv1/8Ur4aoLWa3yyKk5 hhVgUN+S4rJBxGWvUHr9r3jE2JQvOad2Wre8Jy30/tHO0reyPPKulE/iGhYx4THve4m2 ZSQq3bMmiFxNK6Y9clUYyOgwl41klR2lODmyqt50OFFMvTbeNjuSkz5/TxXuybZpgEq+ e9jPohHov2L68Qv7GW7ljcZIKOR1qxJNcEwa1M0AlONSjbjJZ57SqpxKo6zLkwfpHJE4 Amyw== MIME-Version: 1.0 Received: by 10.43.63.140 with SMTP id xe12mr26977299icb.57.1343246885313; Wed, 25 Jul 2012 13:08:05 -0700 (PDT) Sender: php@golemon.com Received: by 10.64.16.35 with HTTP; Wed, 25 Jul 2012 13:08:04 -0700 (PDT) X-Originating-IP: [2620:0:1cfe:28:bc37:12a0:1470:5837] In-Reply-To: References: <500EDCC7.1020402@ajf.me> <500EE3B9.8010902@ajf.me> <500EEA76.1030407@ajf.me> <5010138D.5050804@ajf.me> <501015B9.6050704@ajf.me> Date: Wed, 25 Jul 2012 13:08:04 -0700 X-Google-Sender-Auth: GY2NK5zLNs7Eg5JPQgTniLe3S1o Message-ID: To: Alex Aulbach Cc: Andrew Faulds , Ferenc Kovacs , Sherif Ramadan , internals@lists.php.net Content-Type: multipart/alternative; boundary=bcaec51b1e3b71dc8904c5ad0993 X-Gm-Message-State: ALoCoQm9lKUcxoCOw2rEellrLSoxUnrzl3Me/xbOvYb4hqGbM+HxObn/udzYz+4wBh7OvITFusls Subject: Re: [PHP-DEV] Re: Generators in PHP From: pollita@php.net (Sara Golemon) --bcaec51b1e3b71dc8904c5ad0993 Content-Type: text/plain; charset=ISO-8859-1 > > Suggestion: > > For a generator, rename the keyword "function" to ... "generator" or > something like that. Example: > generator hugo() > { > yield ... > } > > As Nikita pointed out, having a T_GENERATOR token will cause side-effect problems from namespace collisions. This is a concern any time you add a keyword to the PHP parser. > Fact: yield/generators is more or less complicated, this shouldn't be > changed - it's a proven concept. > Speaking of parse errors, I'm having trouble parsing this line. I *think* you're saying that generators are just complex things and that's the way it should be. I... guess I agree, though I have a lower opinion on the complexity of generators. Seem like a fairly straightforward concept to me. They are certainly proven concepts. Fact: yield makes functions some kind of "different". > Yes, they turn normal functions into continuation functions (functions which can be exited and reentered dynamically). > Fact: It doesn't matter how it is implemented in other languages, > because we talk about PHP and not other languages. > Disagree somewhat. Part of PHP's ease-of-use it it's similarity to other languages so that a developer working on C or Perl or Java or what-have-you, can look at PHP code for the first time and have a pretty good idea of what's going on. Mirroring existing implementations should certainly be a consideration for that purpose. Not the end-all decider, but a consideration. > Fact: This is also good style in general: Call the things what they are. > I'll grant this point has merit, however it has two counter-arguments. (1) T_GENERATOR naming conflict mentioned above. (2) Generators *are* still functions, so the name "function" isn't a misnomer. They're just a special type of function similar to how methods are special types of functions, but we still label them as "function". > Fact: as PHP-developer we must try to avoid making things more > complicated, because this is one of the best features of PHP. > Agreed. And a generator is far less complex than a full iterator implementation. Further, continuation functionality is far less complex than building in loop counting logic to an iterator's next() method. > Fact: it's easy to implement a new keyword into PHP for that case > False. See above. > Experience: Most PHP programmers will have problems to understand > generators because it is a function that generates an iterator... something magic they never heard of before. > Fact: PHP's manual is the best in the industry. PHP developers know this. PHP developers are smarter than you give them credit for. > Experience: generators/yield can't be explained on one page. Much > programmers will never ever read so much docs. :) > The core of what a generator is can be explained in a single paragraph with a few examples - Just like nearly every page in the PHP manual. If we can't give PHP developers that much credit, then we should shut the project down now. > Experience: good features are self-explaining. A function which > returns an iterator because of a simple word in it's body is not. A developer who's never seen the yield keyword before need only learn what it is once. http://php.net/yield Problem (to be) solved. > Experience: They will make stupid mistakes, because they mix yield > function with normal functions. > And the compiler will slap them for it. > Experience: They will make stupid mistakes, because they will look for > "return" instead for "yield". > And they won't find it, but hey look, what's this yield thing, I wonder what that does: http://php.net/yield > Experience: Not using the same name will remove a little bit pressure > from "busy" programmers > Developers who work with other people's code (and that's who you're talking about) routinely have to spend time understanding the purpose of a given function. To assume that one can pretend to understand a function without having seen and questioned an unfamiliar keyword like "yield" is ridiculous from the outset. If this hypothetical developer wants to understand the function, they'll see it's got yield and learn that's what makes it a generator. If they don't want to understand the function, then putting up a big sign isn't going to help the matter whatsoever. > Experience: The current concept dosn't "feel right" for me. I like to > listen to my belly in those questions, because he is in most cases > right. With the change I suggested he stops grumbling. > Fair enough. Unfortunately, for the reasons stated above, it's just not that simple. --bcaec51b1e3b71dc8904c5ad0993--