3 ms·
> It is by design that the default parameter to a function parameter is evaluated only once, as the alternative has bad performance implications. Do people act
by mindslight 18y ago
> It is by design that the default parameter to a function parameter is evaluated only once, as the alternative has bad performance implications.
Do people actually use the results of long-running or side-effectful functions as default parameters? It seems the only time this issue comes up is when people get tripped up by mutating simple [] or {} default parameters.
I would expect a default expression to be simple and pure. If this expression should only be executed once, requiring a programmer to be explicit about the complexity wouldn't be a bad thing.
- etal 18y agoIt can be a cute hack to get around the absence of static variables. Lists have other quirks related to mutability; there are other obscure Pythonisms that use this. If you want a nice magic-free immutable container, tuples are a better bet.
- ivankirigin 18y agoI often evolve type in a single var into something more complex, foo = makeSomethingDifferent( foo ) And I need to catch myself when foo is a default param