[Python-checkins] CVS: python/nondist/peps pep-0255.txt,1.9,1.10

Tim Peters tim_one@users.sourceforge.net
Thu, 21 Jun 2001 09:56:43 -0700


Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv19871/peps

Modified Files:
	pep-0255.txt 
Log Message:
Added BDFL Pronouncement on reusing "def".


Index: pep-0255.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0255.txt,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** pep-0255.txt	2001/06/20 20:56:07	1.9
--- pep-0255.txt	2001/06/21 16:56:41	1.10
***************
*** 303,308 ****
  Q & A
  
!     Q. Why a new keyword?  Why not a builtin function instead?
  
      A. Control flow is much better expressed via keyword in Python, and
         yield is a control construct.  It's also believed that efficient
--- 303,312 ----
  Q & A
  
!     Q. Why not a new keyword instead of reusing "def"?
  
+     A. See BDFL Pronouncements section below.
+ 
+     Q. Why a new keyword for "yield"?  Why not a builtin function instead?
+ 
      A. Control flow is much better expressed via keyword in Python, and
         yield is a control construct.  It's also believed that efficient
***************
*** 328,331 ****
--- 332,366 ----
         for "return expr", it's simply cleaner to use "yield" exclusively
         for delivering values.
+ 
+ 
+ BDFL Pronouncements
+ 
+     Issue:  Introduce another new keyword (say, "gen" or "generator") in
+     place of "def", or otherwise alter the syntax, to distinguish
+     generator-functions from non-generator functions.
+ 
+     Con:  In practice (how you think about them), generators *are*
+     functions, but with the twist that they're resumable.  The mechanics of
+     how they're set up is a comparatively minor technical issue, and
+     introducing a new keyword would unhelpfully overemphasize the
+     mechanics of how generators get started (a vital but tiny part of a
+     generator's life).
+ 
+     Pro:  In reality (how you think about them), generator-functions are
+     actually factory functions that produce generator-iterators as if by
+     magic.  In this respect they're radically different from non-generator
+     functions, acting more like a constructor than a function, so reusing
+     "def" is at best confusing.  A "yield" statement buried in the body is
+     not enough warning that the semantics are so different.
+ 
+     BDFL:  "def" it stays.  No argument on either side is totally
+     convincing, so I have consulted my language designer's intuition.  It
+     tells me that the syntax proposed in the PEP is exactly right - not too
+     hot, not too cold.  But, like the Oracle at Delphi in Greek mythology,
+     it doesn't tell me why, so I don't have a rebuttal for the arguments
+     against the PEP syntax.  The best I can come up with (apart from
+     agreeing with the rebuttals ... already made) is "FUD".  If this had
+     been part of the language from day one, I very much doubt it would have
+     made Andrew Kuchling's "Python Warts" page.