Avoid This Python Anti Pattern At Any Cost .

--

Python Anti-pattern : Impure(IO) Default Arguments

One of most liked features of python functions is default arguments . We use them
every day . But there is gotcha that you need to take care .

Function default arguments are evaluated at module load time rather than function invocation time .
Which helps with perfomance benefits when the default arguments are static and deterministic .

So if your function is non-deterministic or has side-effects, you could run into trouble.
As the example shows, the printed time is frozen; it was set once when the code was first evaluated.

Thanks ..

--

--

Imperative coder.
Imperative coder.

Written by Imperative coder.

I am a coding enthusiastic and Tech addict.

No responses yet