Live data from Hacker News

Anti-Patterns in Python Programming

lignos.org

241–242 of 242 posts

Re: Anti-Patterns in Python Programming

#241
post #183

Earlier quoted context omitted.

In Python 3 there's the nonlocal keyword to deal with the scoping thing. The default arguments thing is worse than a lot of the stuff Python 3 corrected.

I don't see how nonlocal could fix this. Could you explain? More specifically, given a better 'default arguments thing', how would you interpret: x = [2] def f(x=x*5): x.append(4) With the earlier conversion it's: x = [2] def f(x=DefaultArg): if x is DefaultArg: x = x*5 x.append(4) This isn't going to work because the x inside of f() is different than the outside x, and you'll get the error message I mentioned. If yo…

Ah I see. Yeah nonlocal can't fix that.

Re: Anti-Patterns in Python Programming

#242

Earlier quoted context omitted.

I think you are trying to justify your strange preferences after the fact. How exactly were there bugs caused by nested for loops that you encountered? It's not like if you mess up the order it will actually run without throwing an exception. Nested list comprehensions are idiomatic python. It's really strange that you don't let your team use them because you are afraid of them.

Well, Google doesn't recommend it either ( http://google-styleguide.googlecode.com/svn/trunk/pyguide.ht... ), but I guess they are all bloody noobs or whatever. I mean, single level comprehension is good. Nested list comprehension is OK only in most trivial cases. In my opinion, if I see how a person uses list comprehension, I can tell, what kind of person this is. There are people who, for example, do this def all_i…

If you think two loops is not a "simple case" of a list comprehension as Google suggests to use them for, perhaps you shouldn't be doing code reviews. It sounds like your team would be held down by your weak grasp of the language.
Post reply on HN