[Python-ideas] Default arguments in Python - the return
spir
denis.spir at free.fr
Sat May 9 12:42:56 CEST 2009
Le Fri, 08 May 2009 22:31:57 +0200,
Pascal Chambon <chambon.pascal at wanadoo.fr> s'exprima ainsi:
> And no one seemed to enjoy the possibilities of getting "potentially
> static variables" this way. Static variables are imo a rather bad idea,
> since they create "stateful functions", that make debugging and
> maintenance more difficult ; but when such static variable are,
> furthermore, potentially non-static (i.e when the corresponding function
> argument is supplied), I guess they become totally useless and dangerous
> - a perfect way to get hard-to-debug behaviours.
If we want static vars, there are better places than default args for this. (See also the thread about memoizing). E.g. on the object when it's a method, or even on the func itself.
def squares(n):
square = n * n; print square
if square not in squares.static_list:
squares.static_list.append(n)
squares.static_list = []
squares(1);squares(2);squares(1);squares(3)
print squares.static_list
Denis
------
la vita e estrany
More information about the Python-ideas
mailing list