News for hackers. Stuff that matters.
Re:Anti-Patterns in Python Programming by mark-r on Thursday July 10, 2014 @11:33AM (#8015305)
I've seen this trotted out time and time again, and at least in this simplified form it's a red herring. If you're going to mutate the argument, it doesn't make sense to give it a default value. If you're going to return a modified form of the input you need to make a copy of it. Doing both is simply absurd.
Re:Anti-Patterns in Python Programming by pbh101 on Thursday July 10, 2014 @12:07PM (#8015429)
Disagree. Would say it's a decent violation of expectations for the same instance to be passed into every invocation. Of course, the counterargument is 'know your tools,' which I'm partial to, but the fact that this pops up is an indication it is counterintuitive.
Re:Anti-Patterns in Python Programming by mark-r on Thursday July 10, 2014 @01:34PM (#8015958)
I actually agree it's counterintuitive. But this particular example makes no sense, nobody should be writing real-world code that looks like this in the first place. Either modify the original or return a copy, don't try to do both.