Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at CFUNITED 2008 (Washington, D.C.) with:

Name vs. Variable In ColdFusion

By Ben Nadel on
Tags: ColdFusion

There are a good number of tags in ColdFusion that return a value into a variable defined by one of the tag attributes. While you might not think about it, the attributes that define the return variable (excluding the Result attribute of things like CFHttp and CFFile) fall into one of two main categories:

  • Variable
  • Name

Now, as you might know, I try to avoid using intellisense as much as possible. I definitely take pride in remembering as much of the ColdFusion syntax as I can. And, while I have been coding ColdFusion for a long time, I definitely get tripped up from time to time in remembering which tags use Name and which tags use Variable to define the return value. And so, in order to sharpen my own mental-intellisense, I thought I would write these tags down and then see if there was any common theme I could use to train my mental processes. Here are the tags that I could find:

Variable Attribute

  • CFSaveContent
  • CFFile
  • CFXML
  • CFZip (read / read binary)

Name Attribute

  • CFQuery
  • CFDirectory
  • CFHTTP (query)
  • CFFTP (query)
  • CFZip (query)
  • CFDocument
  • CFFeed
  • CFImage

Output Attribute

  • CFWDDX

I thew in the CFWDDX tag just because it stood out as the very different one. I rarely ever use WDDX so I am not even gonna waste the brain power on it. Plus, I think its a really old tag, so I definitely wouldn't think it would stick to any established standard.

But, let's look at the list of Variable vs. Name attributes. The first thing that pops out is that all tags that can return a ColdFusion query object use the Name attribute. So that's rule #1: query equal name attribute. The second thing that pops out at me is that any text-related return value uses the Variable attribute. This is a bit of a stretch since CFFile and CFZip can both return binary reads, however, they can also return text-file reads. CFSaveContent definitely returns text. CFXML returns an XML Document, but think about it like this - XML is really just a text format and yes, an XML Document is not a text value, but it represents a structured text value. So, I think that's rule #2: text-like equals variable attribute. Of course, you could say the same thing about CFFeed and structured text.... well, I'm just trying to find the most common ground here, plus I heard you drink you own pee, which is kind of gross.

Having written these down and grouped them, it looks like this might not be too bad. I am gonna say that these are the basic rules (with one or two exceptions):

  1. Text based data / data reads are stored in Variable-defined values.
  2. Query and other complex data values are stored in Name-defined values.

Yes, that doesn't quite work across the board, but I feel much more comfortable know this.

Tweet This Interesting post by @BenNadel - Name vs. Variable In ColdFusion Thanks my man — you rock the party that rocks the body!


Reader Comments

on a different note in the same tune, the one that always gets me is the use of 'item' in cfloop when you're looping over a collection. I've become conditioned to writing 'index' in my cfloop tags. although I don't have the problem when looping over a query or doing a conditional loop. I guess the fact both attributes start with 'i' and are vaguely similar...

Reply to this Comment

Just wanted to comment something on the cfwddx tag; the cfwddx tag uses the WDDX standard that was created in 1998 by Simeon Simeonov from Allaire. WDDX was first used in Cold Fusion (back when it was two words) and was released publicly a year later. It's a really useful tag for saving/reading configuration files because it defines structures, arrays, strings, and numbers that convert directly to CF elements.

Reply to this Comment

Yup, I'd agree with the comment on WDDX's usefulness. It's great if you need to serialize/deserialize a complex variable in order to store it somewhere for later retrieval. For instance, we use it to store someone's workflow state in our database so that they can log out, then come back later and restore their session. I also use it to save a user preference struct to the server's hard drive for some applications that don't depend on a database.

Reply to this Comment

@Duncan,

I definitely make that mistake a lot. I just remember that collection looping is the exception.

@Robert,

The CFWDDX tag is definitely a good tag. I have used it a lot of the course of time (not lately). I have created XML-databases that rely on it heavily. It is pretty awesome that it goes from XML directly to ColdFusion structures. It is good stuff.

Reply to this Comment

@Patrick,

Good call. I'm so used to using CreateObject() that I fogot CFInvoke had a return variable. That's way different than the rest.

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.