The Benefits of Named Arguments When Calling CFC Methods
On the whole I'm a pretty big fan of minimizing the typing within an application, but I'm starting to move quite a few of my method calls to using named arguments because of the benefits they can provide over unnamed (positional) arguments . . .
One of the first benefits of named arguments is that it makes your code more readable. For methods with lots of arguments, sometimes it is nice to see the name of all of the arguments right there in the method call rather than having to jump back and forth between the caller and the called classes to see the arguments being passed.
Secondly, named arguments (or using an argumentsCollection) is the only way to have multiple optional arguments and to have some method calls including one optional argument and other method calls including another.
Finally, if you're using delegates, named arguments has the minor benefits that you don't *have* to put any of the cfargument statements in the delegate methods as I found out earlier today - keeping your code just a little DRYer (but not for free - see cautions in the posting).
Of course, you get all of these benefits if you use an argumentCollection, and for simple methods where there are a small number of arguments most of which are required, this isn't a big deal - I can't imagine using named arguments for getters and setters, for instance. But for larger, more complex methods, I'm finding the move to named methods to be quite useful.
What is your take? How do you decide between named arguments, an argumentCollection and simple unnamed/positional arguments for a given method?



Man, it took me a while to read through all of today's posts! Sorry if I don't reply on everything, there's a bunch of stuff I need to digest to fully comprehend. This blog is quickly turning into my favorite, I feel like I learn tons just by reading it. Thanks a lot of all the posts.
I can see that even though I got in at 5:30, it was useless, since you seem to have posted enough to keep me busy until noon =)... good to see you posting quality material at that furious pace again. Bad for my work efficiency.
On a somewhat similar note, I do like the idea of using coldspring with named constructor injection and having it just set everything passed in though by looping through the arguments. Basically all my init methods just super() up to the base one which sets whatever arguments are passed in. Saves some time assuming you don't have circular dependencies.
@Adam, Of course, if you ONLY have super.init() in your inits, you can just remove the init() methods and the parent one will be called automatically . . .
http://www.cfinternals.org/blog/2007/05/named_argu...