The same thing applies to anything which 'handles events', including servers, games, GUIs, CLIs, etc. In general, any time we might write a "main loop" like:
foo = lambda z: ....
bar = lambda x: ....
baz = lambda y: ....
def main():
z = init
while true:
x = foo(z)
y = bar(x)
z = baz(y)
This is equivalent to having each step perform a tail-call to the next one:
foo = lambda z: bar(....)
bar = lambda x: baz(....)
baz = lambda y: foo(....)
main = lambda : foo(init)
The latter form has better encapsulation, requires no mutable state, doesn't have stale/out-of-date variables, etc.
The fact that infinite recursion is seen as a bug, yet "while true:" loops are common, is a symptom of this negative feedback loop which keeps people from learning and using recursive solutions.
The fact that infinite recursion is seen as a bug, yet "while true:" loops are common, is a symptom of this negative feedback loop which keeps people from learning and using recursive solutions.