programming-languagestheoryformal-languages

Can function arguments be freely interchanged without affecting program behaviour?


This is a question applicable a statically typed language that has functions (no optional parameters).

If I have some function that accepts, say, 5 parameters of types a, b, c, d, e in the following form:

function(a, b, c, d, e) {
    does things
}

// call syntax:
function(a, b, c, d, e);

Is it (theoretically) equivalent if I modify the function to accept the parameters in different order, given that I call it in that order?

function(e, a, d, b, c) {
    does things
}

// call syntax:
function(e, a, d, b, c);

Is there actual academic work on this matter or should the answer be trivial? (I'm not experienced with formal programming languages)


Solution

  • If, in the language, arguments can be function calls, and those functions can have side-effects, then putting those arguments in a different order will probably result in different behavior. (The language definition might say that the behavior is undefined in such a situation.)