Say I have something like this sample code.
def foo(n):
def bar():
return -1
if n = 0:
return 0
else:
return foo(n+bar())
I assume it creates a new instance of bar every time foo is recursively called. However this seems like something that could be optimized in python (or any other language) but I was unable to find anything stating if it has been optimized for that.
The reasoning I have bar defined in foo is I'm trying to hide bar from the user and python's _bar() or __bar() of "please sir don't use this dear user" is annoying me as I was trained in non scripting languages.
__all__global variable of your module. Python doesn't have "real" private functions. If a user wants to accessbar, there's no point in slapping them and saying they can't do that.The reasoning I have bar defined in foo is I'm trying to hide bar from the user and python's _bar() or __bar() of "please sir don't use this dear user" is annoying me as I was trained in non scripting languages.If you're using an interpreted language they could just get to your code anyway. Why do you feel the need to hide it so thoroughly.