4 ms·
Passing null instead of empty collections is a practice that should be discouraged imho. There is an entire design pattern ("Null object" [1]) that's making the
by gnoack 6y ago
Passing null instead of empty collections is a practice that should be discouraged imho. There is an entire design pattern ("Null object" [1]) that's making the point that you should use a "neutral" object instead.
But it happens anyway sometimes, of course :)... in Python, I've also often used the `or` shortcut for that, like this
for item in stuff or []:
var_dump(item)
or just at the top of the function, reassigning the function argument:
stuff = stuff or []
[1] https://en.wikipedia.org/wiki/Null_object_pattern https://en.wikipedia.org/wiki/Null_object_pattern