[Python-Dev] anonymous blocks

Shane Holloway (IEEE) shane.holloway at ieee.org
Wed Apr 20 18:32:17 CEST 2005

Aahz wrote:
> On Tue, Apr 19, 2005, Shane Holloway (IEEE) wrote:
>>However, my opinion is that it does not read smoothly.  This form 
>>requires that I say what I'm doing with something before I know the 
>>context of what that something is.  For me, blocks are not about 
>>shortening the code, but rather clarifying *intent*.  
> Hmmmm....  How is this different from defining functions before they're
> called?

It's not.  In a function scope I'd prefer to read top-down.  When I 
write classes, I tend to put the public methods at the top.  Utility 
methods used by those entry points are placed toward the bottom.  In 
this way, I read the context of what I'm doing first, and then the 
details of the internal methods as I need to understand them.

Granted I could achieve this effect with::

     class Before:
         def readIt(self, filename):
             def readIt():
                 withFile(filename, doReading)

             def doReading(aFile):

             return readIt()

Which is fine with me, but the *intent* is more obfuscated than what the 
block construct offers.  And I don't think my crew would appreciate if I 
did this very often.  ;)

More information about the Python-Dev mailing list