On Sun, Jun 30, 2013 at 2:32 PM, Terry Reedy <tjre...@udel.edu> wrote: > On 6/29/2013 5:21 PM, Ian Kelly wrote: >> >> On Sat, Jun 29, 2013 at 2:53 PM, Terry Reedy <tjre...@udel.edu> wrote: >>> >>> # The alternative for either program or people is a 1-pass + backtracking >>> process where all understandings are kept provisional until the end of >>> the >>> body and revised as required. 2 passes are simpler. >> >> >> Or simply an explicit declaration of scope at the beginning of the >> function definition. > > > One of the reasons I switched to Python was to not have to do that, or > hardly ever. For valid code, an new declaration is hardly needed. Parameters > are locals. If the first use of another name binds it (and that includes > import, class, and def), it is local. If the first use of does not bind it, > it had better not be local (because if it is, there well be an exception). > If there are branches, each should be consistent with the others. One should > only need two readings to understand and fix unbound local errors.
This is strictly a matter of opinion, and one on which mine differs from yours. I think explicit declarations are better than implicit "you've assigned to this name" local creations; the declarations help to catch typos. Also, I like the consistency of C-style declarations - where-ever you declare something, it's valid from there "in", and not "out". Without declarations, there's a magical scope boundary at a function definition that's different from the non-boundary at a loop, for instance. But that's just my opinion. and as Teresa says, I'm only one, and possibly I'm wrong. ChrisA -- http://mail.python.org/mailman/listinfo/python-list