On Tue, Apr 19, 2005, Shane Holloway (IEEE) wrote: > > I heartily agree! Especially when you have very similar try/finally > code you use in many places, and wish to refactor it into a common area. > If this is done, you are forced into a callback form like follows:: > > > def withFile(filename, callback): > aFile = open(filename, 'r') > try: > result = callback(aFile) > finally: > aFile.close() > return result > > class Before: > def readIt(self, filename): > def doReading(aFile): > self.readPartA(aFile) > self.readPartB(aFile) > self.readPartC(aFile) > > withFile(filename, doReading) > > Which is certainly functional. I actually use the idiom frequently. > 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? -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code -- not in reams of trivial code that bores the reader to death." --GvR _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com