Scott David Daniels <[EMAIL PROTECTED]> wrote: > Steven D'Aprano wrote: > > On Sat, 23 Jun 2007 21:11:42 -0700, Alex Martelli wrote a lot, with lots > > of YELLING. > > > > Given the amount of SHOUTING in your post, and the fact that you feel so > > strongly about the trivial question of the redundant use of the global > > statement that you would "fail a student" who did it -- even if they did > > everything else correctly, efficiently and elegantly -- it seems to me > > that you are beyond rational discussion on this subject. > > I, for one, appreciate a second voice suggesting that your (Steve's) > vehement rejection of my technically correct and non-condemnatory post > explaining that one use of global in the OP's code was superfluous.
Glad to hear this! I think the root of the issue is in learning to read "superfluous" as a NEGATIVE word -- follow Occam, and learn to not multiply entities beyond need:-). > You said (in the previous post): > > That's technically true, but declaring it with global makes the code > > self-documenting and therefore easier to read. > > > > It's never _wrong_ to use the global statement, even if it is strictly > > unnecessary for the Python compiler. > > Your post led a newbie to presume the extra use of global was "good > style," while I think you'll find there is no such consensus. I concur: having discussed style issues at many Python shops, I'm quite convinced that the general consensus is closer to the "redundant is bad" approach. Exhaustively listing all of the redundancies that are to be eschewed would of course take far too long; a more common approach is to try to identify those extremely few cases where redundancy IS explicitly deemed OK (and leave all other redundancies intrinsically disapproved). The cases I've seen with reasonable frequency for accepting certain redundancies basically boil down to accepting some "redundant parentheses". Python has many levels of priorities in expressions, and while they do tend to work "just right" there are always some corner cases where even a frequent Python coder MAY feel uncertain for a moment (and these uncertainties grow for coders that also have to use, e.g., C, or Fortran, &c, frequently). So, spelling things out as, e.g., (-a) ** b versus -(a ** b) is not unreasonable (vs just coding '-a**b' and relying on the reader to know exactly which of the two cases applies). An important subcase has to do with tuples -- while I personally prefer to use parentheses around tuples only where they're indispensable, I understand the opposite stance, where parentheses are always placed around tuples (it may be hard to memorize exactly all cases where they're required, e.g. when the tuple is the expression in a listcomp...). A more debatable case, IMHO, is slicing (and the related cases of range and xrange). Do you ever write x[0:N:1], xrange(0, N), etc? Or are the simpler x[:N], xrange(N), etc, always to be preferred? This is one of the few cases where I've seen group consensus fail to emerge in discussions about Python style even in close-knit teams... Alex -- http://mail.python.org/mailman/listinfo/python-list