Thursday, January 14, 2010

"var scope" for CFC Function Variables

Why is it good practice to always "var-scope" every CFC function variable?
  • Make it clear that the variables are only visible within the function;
  • Using "var-scope" actually can help improve performance. I tried the test here, and am personally convinced that "var-scope" has significant positive impact on performance;
  • If you "var-scope" every CFC function local variables, then it will be obvious when you have typo in your code. Because you can use tool like "varScoper" to scan your file, if there are complains, you either forget to "var-scope" a variable, or you've got a typo that "varScoper" just helped you to catch;

No comments: