Three Reasons to Scope Function Calls to the Same Component

A long time ago when I was a beginner ColdFusion programmer I didn't use scopes unless I really needed to. I think my reasoning was that "If it works, why add the extra code just to specify the scope?" or something like that. Nowadays I scope pretty much everything but there is one remaining area where I haven't bothered with it yet - function calls to the same component you're currently in.

Well, this is about to change (both in my application code and in the Wheels framework). Here are three good reasons why I'm making this change:

Performance

Based on some quick testing, using the "this" scope when making internal function calls within the same component is about 10 to 15 percent faster than leaving them unscoped. Here's the code if you want to run it on your system:

Readability

When prefacing the method call with "this" you are making it more obvious to other programmers looking at your code that you're calling a function on the same component rather than some built-in CFML function for example.

Flexibility

If you're a heavy user of the awesome "OnMissingMethod" function you may have noticed that you can't invoke it from within the same component. Unless you use the "this" scope that is!

Note that when you're calling an internal private function you should use the "variables" scope instead of the "this" scope.

Per Djurner

Per Djurner

Working with ColdFusion, JavaScript, ActionScript, SQL, CSS, HTML and more at SingSnap.

Archive

2012 (1)
2011 (1)
2010 (6)
2009 (1)
| Viewed
times
Posterous theme by Cory Watilo