I prefer not to set function local variables to an specific type until I'm
actually about to use them. I alwasy initialize them to an empty string if I
can't initialize them to their final value. That is, I will initialize
structures and arrays up front if I know they will definitely hold a value
at some point. Otherwise I will initialize them to an empty string.

There are 3 reasons.

1. I'm lazy and it's a bit slower to type queryNew('unknown') etc. Then I
run into internal conflicts saying that if I'm going to create the query, I
really should give it the right columns. That then leads to a bit more
maintenance overhead if I need to change which columns the real query is
returning.

2. There is a pretty much negligible performance overhead, but given that
the more performant way also allows me to be lazier I tend to follow that
path.

3. If I ever change the type of the variable, say from a query to an xml
file, I have one less place where I might forget to update the reference and
so introduce a sleeping bug. On the surface you might think this is still a
problem if I change from using a structure to an array, but in that case you
usually have to go back to the point where the variable is initialized in
order to make the change at all.

I occasionally mull over the wisdom of initializing any local variables to
anything other than an empty string for the reasons I mentioned in point 3,
but so far it hasn't bitten me, and again, it allows me to follow the path
of the lazy coder. Only doing things where necessary.

My 2 cents

Spike

--------------------------------------------
Stephen Milligan
Code poet for hire
http://www.spike.org.uk

Do you cfeclipse? http://cfeclipse.tigris.org 


 

>-----Original Message-----
>From: [EMAIL PROTECTED] 
>[mailto:[EMAIL PROTECTED] On Behalf Of Bryan F. Hogan
>Sent: Tuesday, July 20, 2004 12:43 PM
>To: [EMAIL PROTECTED]
>Subject: Re: [CFCDev] Making Persistant CFCs thread safe
>
>This is totally acceptable. Neither way suggested is best, best is the 
>fact that variables should be var scoped, which you correctly do. When 
>it comes to the preferance on setting the types it just that, a 
>preferance, not good or bad, it depends on the methodology 
>that you are 
>using.
>
>Stacy Young wrote:
>
>> For queries I normally initialize as a string (maybe not 
>best but works)
>> 
>> <cfset var myQuery = "" />
>----------------------------------------------------------
>You are subscribed to cfcdev. To unsubscribe, send an email
>to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
>in the message of the email.
>
>CFCDev is run by CFCZone (www.cfczone.org) and supported
>by Mindtool, Corporation (www.mindtool.com).
>
>An archive of the CFCDev list is available at 
>www.mail-archive.com/[EMAIL PROTECTED]

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

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

Reply via email to