I am considering segregating methods into functions and procedures. A function is side effect free. Like a mathematical function it transforms set of input values into an output value. On the other hand, a procedure may have statements with side effects, like assignment statements or output.
Questions:
- What advantages are there to this conceptual segregation?
- Should functions really be side effect free, or might they be a bit more capable? I think it would be okay to permit certain side effects, like assignment to a local variable—side effects which do not change the state of the rest of the program.
Functions could provide all kinds of benefits—expression statements? would be limited to function calls only.
return for each x in container:
sqrt(x) < 10;
In fact, this could be the way to distinguish between expression and non-expression versions of a statement. An expression statement contains only function calls, whereas a non-expression statement can contain procedure calls but is more restricted in usage.
It's not necessary to limit expression statements to function calls alone, however. Question: Are there any useful uses of side effects in expression statements that this constraint would prevent?