Function Naming and Scope in ColdFusion MX 7
A couple of times recently I have seen strange errors when I am building my CFCs. At first I thought it had something to do with issues with the APPLICATION scope, or the caching I have been doing with my framework. It turns out however, that I indeed am not having problems with my ColdFusion installation. Instead I am having problems with my own laziness.
For a long time I have been a firm advocate of self-documenting code. That is naming variables with prefixes that indicate what type of data is contained within the named variable. For example if you ahve a string with the value “my name” you would call the variable strName in your cfset statement. That way whenever you see the variable, you will know what data type it is. This is a very handy way to keep track of your instances and objects in a loosely typed language.
The problem that I have come across is that I have been lazy and I haven't been using name spaces the way I should. Namespaces are creating structs for your variables, like variables.strName. I am breaking a nasty habit of naming my encapsulated query functions the same thing as my cfquery statement. So for example, I would to cffunction name=”getStuff” and then to cfquery name=”getStuff.” Then when I execute the object I get the error, “The name getStuff is not the name of a function. This error kept me perplexed for a little while until I noticed what was going on. This could easily be remedied by doing cfquery name=”query.getStuff” and cffunction name=”funct.getStuff.” Since they would be using different namespaces I wouldn't have the problem, but I would still be able to maintain my function naming conventions.