The swapping with temporary variables is error prune.
Here an example with swapping:
In bigger projects, this is the opening of hell's gates. You deserve what you get.
In earlier programming languages there was a big difference between functions and procedures. A function is just something to do a calculation without affecting the outside world. A procedure was affecting the outside world, like printing on a terminal or printer.
Here an example with swapping:
def fib(n): a, b = 0, 1 for _ in range(n): a, b = b, a + b yield(a)And now the complicated version:
def fib(n): a, b = 0, 1 for _ in range(n): x = a + b a = b b = x yield(a)Also a function should never change values outside of the function. This leads into an unexpected behavior. You can do this with short code.
In bigger projects, this is the opening of hell's gates. You deserve what you get.
In earlier programming languages there was a big difference between functions and procedures. A function is just something to do a calculation without affecting the outside world. A procedure was affecting the outside world, like printing on a terminal or printer.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!