> Well guess what – you just added the overhead of 100,000 unnecessary 
> object creations.  You’ve also added 100,000 StructInsert() calls (the 
> cfset local.result statement does it implicitly).  Not only does this 
> directly hurt the performance of the code, it also affects the underlying 
> server processes.  That’s now 100,000 additional structs that have to be 
> Garbage Collected!!!

I don't think it's terribly common to see a function called 100,000 times in
a single page request. I can't think of a single app that I own that does
such a thing. Granted, if you do happen to have a bit a code like that, then
avoiding the "local" struct will undoubtedly improve performance.

> Anyway, in this case, you obviously would never want to use the local = 
> StructNew() method, and I run into too many other examples of this type of

> code that make it undesirable to use.  

I think it's far more common to forget to var scope a local variable,
causing leakage into the "variables" scope. The "local" struct can help in
this respect to the extent that unscoped vars will look wrong. It's also
very likely that you'll forget to scope the variable one place and not
another, causing ColdFusion to throw an error.

As a general rule, I use a "local" struct on any function with more than 3
or 4 local scoped variables or any function that is more than a few lines in
length. But that's just a general rule. If I suspect a performance issue,
I'll try removing the "local" struct. If I'm auto generating code, I'll skip
the "local" struct. On the other hand, if I have a simple function with only
2 or 3 local variables but I suspect I'll be adding functionality in the
function, I'll use a "local" struct.

> Not to mention I _like_ seeing all 
> of my variables declared up front.

I do too, in languages that force you to declare your variables (e.g. VB w/
Option Explicit). In ColdFusion, I'm not so particular because there's no
way to ensure that all the variables are being declared at the top of the
function. So, I think it gives a false sense of security ("all the variables
at the beginning of my function are declared with the 'var' keyword
therefore all the variables in my function must be local").

Ben Rogers
http://www.c4.net
v.508.240.0051
f.508.240.0057




----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to