Structures as arguments to CFML functions
The second example improves the readability of the function call by forcing the individual arguments to be named. In doing so however, it sacrifices a little readability in the function declaration itself as it is not immediately obvious what arguments are expected. This sacrifice may be worthwhile because the method is defined only once, while there may be many more calls to the method. The obscurity of the single object argument could be made up for with one single point of documentation.
Why CFML is different
With CFML, we do not need to sacrifice the readability of either the calling code or the function declaration. This is because we have the ability to use named arguments in function calls as well as declarations:
We have a clear, self-documenting function declaration and also a clear function call.
How about passing existing structures to functions?
One seeming advantage of the single structure argument approach is that existing collections of arguments can be passed easily, i.e.
someFunction( options = form ). However, CFML gives us
argumentCollection for this very purpose:
While the function call may be more readable by using named arguments here, this approach can be indispensible and indeed necessary, particularly in more dynamic scenarios.
Before defining a function with a single argument that is a structure of options, think twice. Would that code be more readable by having individual, self-documenting arguments for each of those options? If so, make it so! Anyone have opinions to the contrary?