Re:Reworder – A tale of learning Python and launching an app...
by mixu on Wednesday October 27, 2010 @05:34AM
(#1837902)
Even more simply - are you writing code for a von Neumann architecture (http://en.wikipedia.org/wiki/Von_Neumann_architecture ), or something more abstract?
To my understanding the issue is not whether "state" has side effects (e.g. your global vs. local example), but rather whether there is any concept of "state" (e.g. shuffling stuff from one memory slot to another).
My experience is from Prolog, where the statement "X is X + 1" results in an error, because once unified, the variable X cannot be modified - X is not a memory slot. Once you try to let go of the idea of a machine with memory slots, alternative-paradigm programming gets a little bit easier. Of course in practice state is often needed, so it often gets added through some mechanism.
The dosomething function modified `state` when it changed a global variable. Another function that modifies state is "print()". Generally any function that returns nothing is almost certainly going to modify state outside of it. (Otherwise what is the function for?)
State is memory that is not `local` to the function itself.
The dosomething function here is functional, because the only `state` it modified was local to the function.There you have it.