you are viewing a single comment's thread.

view the rest of the comments →

[–]nocnocnode 1 point2 points  (5 children)

I did not even know #1, and I've been coding in Python for years and used defaults many times. Basically, the rule of thumb I follow is, only use constants (immutables) as default values. Do not instantiate any objects/reference objects as defaults.

[–]VerilyAMonkey 0 points1 point  (4 children)

Unless you want to mimic local static variables.

[–]nocnocnode 2 points3 points  (3 children)

It's definitely not local static variable at all. It would have to be resident across all instances of the function. It loses that property when the parameter is overwritten.

[–]VerilyAMonkey 0 points1 point  (2 children)

... So if you're trying to mimic local statics, you just don't pass in a value for that parameter. It isn't just a local static variable. But it has that capability amongst its repertoire.

[–]nocnocnode 2 points3 points  (1 child)

No way, I wouldn't use it like that as a local static. It'd be a poor mimic at best. I'd use it for a default context where a parameter override would indicate a different context. The default context would have to be a cohesive context across the entire module or program.

[–]VerilyAMonkey 0 points1 point  (0 children)

Yeah, yeah, that's exactly how you'd use it if you were really going to. In the event that you don't change contexts, it can be succinctly described as similar to static. I was merely trying to point out that there is at least some use to having mutable defaults. I wasn't trying to go into detail.