Thursday, April 7, 2011

ColdFusion - Var Scoping.

A couple of days ago I was making a little program to recursively list files in sub-directories.
In doing so I ran into a good example of why var scoping is so important.

File structure:

Non var scoped code:


Non var scoped results:


However when I properly var scoped the variables. 

var scoped code:


var scoped results:


In simple terms, when the function is being run the second time, ColdFusion is being lazy. Instead of making and declaring a new variable it is using the old one. Adding var scoping will make sure that whenever the function is run the variables are scoped to that instance of the function.

3 comments:

  1. Can you please describe why you think ColdFusion is being Lazy.

    ReplyDelete
  2. I think you are taking the sentence a bit too literally. I was being a bit facetious in my use of the word lazy...

    ReplyDelete
  3. Thanks for sharing the post related to ColdFusion Web Services. It is very helpful, you presented the data in very proper manner.

    ReplyDelete