I am not sure if this topic comes under “coding style” and I could not see where it has been addressed here & elsewhere.
The traditional named function definition is an ordered set of comma-separated parameters.
function calculate(
gramMass1,
molecWgt1,
vol1,
gramMass2,
molecWgt2,
vol2
) {
return gramMass1 / molecWgt1 / vol1 * vol2 * molecWgt2 /
gramMass2;
}
For defined functions with a considerable number of parameters, as above, this requires that the arguments be well-ordered in the calling instance.
But suppose instead of function definitions with long parameter lists and their order to memorize, just define the function with an object parameter and the parameters are made properties of the object. One only needs to memorize the property names, which relative easy to do, and now the order of the properties (parameters) is unimportant when calling the function.
function calculate(parameters) {
return parameters.gramMass1 / parameters.molecWgt1 /
parameters.vol1 * parameters.vol2 * parameters.molecWgt2 /
parameters.gramMass2;
}
calculate({
gramMass1: 34.1,
gramMass2: 2.1,
molecWgt1: 170.2,
molecWgt2: 62.78,
vol1: 0.5,
vol2: 1.5
});
This is not innovative of course. The purpose of this post is to ask whether this is an acceptable coding style in general. Are there drawbacks? Would your development team supervisor or enterprise coding standards manual encourage/discourage/insist on/forbid this?