cfargument type of query
I have been working on a component for the past few days with a method that optionally takes in a query as an argument. Initially, I was having some problems in the method because my isQuery() function was not working. Well, here is what I was doing:
<cfargument name="qUserData" type="any" required="false" default="">
<cfif isQuery("arguments.qUserData")>
<!--- do something with the query data --->
</cfif>
</cffunction>
See where the problem is? When I put the arguments.qUserData in double quotes, the function evaluated it out to a string. So, I removed the double quotes and things were better.
I then chatted with a co-worker (and a CF guy who has tons of experience). He mentioned that I could default the qUserData argument as a queryNew("nodata") and just skip the if in the method and loop over the query, because if the query is not there, I wouldn't need to do the "something" in that method, but would do something else entirely. So, the new method looks like this:
<cfargument name="qUserData" type="query" required="false" default="#queryNew("nodata")#">
<cfloop query="arguments.qUserData">
<!--- do something with the query data if we have it --->
</cfloop>
<!--- other code here --->
</cffunction>
I like this way better because I do use typing of my arguments (as does most of my team) when we build or products and APIs. Notice that no IF was required which can save on processing, and the loop will not execute if the recordset is empty. There are tons of different ways to do this, but this is just something to think about.

If you believe that creating a new query object is less expensive than a single if statement, I know a Nigerian Prince you should meet.
I can see your point. What I could have done, and might still do, is create a variabled scoped (attribute) of the component, and have that as the default, so then I only have to create it once, when the bean is put in to application scope in ColdSpring. This component and many of the methods that do this same check, will be called probably up near 1000 times an hour, so yeah, great idea to just create it once! Thanks Rick!
Always with the astute suggestion. Always on the ball.