| ▲ | semi-extrinsic 5 days ago | |||||||
Functions return a value, subroutines do not. So functions can, at the whim of the compiler, cause an extra copy. Style wise, many prefer to reserve functions for things that resemble mathematical functions (i.e. only intent(in) and pure). In some sense a little bit similar to how people tend to use lambdas in python. | ||||||||
| ▲ | adrian_b 4 days ago | parent [-] | |||||||
In a well designed programming language, the compiler should always decide at its whim, whether input or output parameters need an extra copy or not, i.e. if they should be passed by value or by reference. The programmer must only specify the behavior of the parameters, i.e. if they are input, output or input-output parameters, like in Ada. The fact that a parameter is the result is just a matter of syntax, not of semantics. Any other output parameters should behave exactly like the result. This means that for any output parameter, like also for the result, the compiler must decide between receiving the output value in a register or passing an extra pointer on input that is the address of a memory area where the function must write the output value. | ||||||||
| ||||||||