Sam Farmer

Growing up I never imagined I would play bass guitar for the Dave Matthews Band. And indeed it never happened.

But I have become passionate about making software.

Liking using implicit arguments for ColdFusion 9 functions

April 13, 2010

Each new version of a computer language inevitably brings about changes, mostly for the better, in the style of writing that language.

One change I have enjoyed with ColdFusion 9 is using implicit structures as arguments to a function.  This leads to bundling of arguments into structures in cases where it makes more sense.  Granted this has been going on in languages like JavaScript (and even the ColdFusion Javascript functions!) for a long time.  There are definitely good and bad reasons to use this style.

Lets take a function, written with arguments individually defined, and see how this works:

function getAndCache( url, cacheType, cacheTime, cacheContent )

That can be rewritten to:

function getAndCache( url, cache )

This time we put all the cache settings in the cache argument.

Advantages:

Disadvantages:

As I mentioned earlier I'm not suggesting using this for every function but for those that have a collection of config or style options it can work well.  This is seen in a lot of JavaScript functions and used widely by jQuery.


No Comments

Some comments have been lost over the years due to moving hosts.

More


More blog entries that I have written.

Code coloring by PRISM.