I've been writing UDFs for a long time - CFLib was begun when ColdFusion 5 was still in development. But I have to tell you - this one surprised me. Without checking the docs or writing code, tell me what the following script will do:
<cfscript>
function foo(name) {
return "beer";
}
</cfscript>
<cfdump var="#foo()#">
If you answered, "Will throw an error, oh hairy one!", then you would be.... wrong if you are using ColdFusion 9. From ColdFusion 5 to ColdFusion 8, the existence of a argument in the method signature has always implied the argument is required. The docs made this clear (and thanks go to Sam Farmer for digging up these links):
http://livedocs.adobe.com/coldfusion/8/htmldocs/UDFs_03.html#1193711
Names of the arguments required by the function. The number of arguments passed into the function must equal or exceed the number of arguments in the parentheses at the start of the function definition. If the calling page omits any of the required arguments, ColdFusion generates a mismatched argument count error.
However, in ColdFusion 9, the docs change:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSE99A664D-44E3-44d1-92A0-5FDF8D82B55C.html
Specifying the required keyword makes the argument mandatory. If the required keyword is not present then the argument becomes optional.
So to make the UDF above work like ColdFusion 5-8, you must change it to:
<cfscript>
function foo(required name) {
return "beer";
}
</cfscript>
<cfdump var="#foo()#">
Personally I don't think this is a huge big deal. Any code that required name would fail as soon as you didn't pass it. But it's something you want to watch out for.
P.S. If you are curious about the first version and what became of name - it existed as an argument but had a null value.
Archived Comments
Yet another reason for me to continue to write CFCs in tag format. I think I must be one of only a handful of people in the entire CF space that detests cfscript in general and script-only CFCs specifically.
@Dan: So, how do you feel about script based code? ;)
One thing I like about ColdFusion 9 is the ability to use both tags and script based on developer/team of developers preference. Choice is good!
I agree with @Sam that choice is good (personally I've been a tagger for so long that I'll probably continue to work that way).
And since we're talking about arguments, keep in mind that if you write everything in CFCs (and I pretty much do) and if you are writing your methods so that they can be consumed as web services then ALL of your arguments are assumed to be REQUIRED when your method is invoked from the outside world as a web service.
I'd assume the code inspector would check this as part of the compatability checks... or does it?!
Personally I think this tweak in 9 is the beez neez. I've been a script monkey for years, so I'm onboard the new feature.