If the question is whether or not to scope your variables, the answer is:
always scope your variables.

Scoping does a couple of things.  One, it improves codes readability
immensely. Imagine the following code in a 1500 line template:

<cfelseif IsDefined('lPageID')>

Someone who is unfamiliar with the code will have no idea where this is
supposed to be coming from.  Isn't this easier:

<cfelseif IsDefined('url.lPageID')>

Now it's obvious that the code is looking for a URL variable.

Second, it removes a bit of overhead.  If you don't scope a variable, CF has
to search through all of the variable scope types to figure out which one
this relates to.  Obviously if you tell CF where to look, CF doesn't have to
work so hard.

[Note:  I'm not completely sure if this is true.  Any gurus out there?  Does
CF still examine all scopes when identifying scopeX.variable?  I'm thinking
about the differences in housekeeping between local and global vars more
than anything else here, EG, session.var vs. variables.var]


As to the example, I'd rewrite it as:

<CFIF LEN(form.var)>

Here you're doing a numeric calc, as opposed to a string comparison.
Numerics are much faster.  IE; LEN(scopeX.somevar) will evaluate to either 0
(no content) or the length of the variable.  If it's 0, CFIF evaluates to
false, otherwise it's true.  Very quick, easier to type, and IMO, it's
easier to read.


Good luck!

Jeff


-----Original Message-----
From: Phil Labonte [mailto:[EMAIL PROTECTED]]
Sent: Sunday, June 18, 2000 9:41 AM
To: [EMAIL PROTECTED]
Subject: CFIF syntax debate (kind of...)


This is a multi-part message in MIME format.

------=_NextPart_000_0032_01BFD909.54A70BF0
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

When using CFIF and using a variable from a form is it better to refer =
to the variable using ex:  <CFIF Form.Var is not "">  or can I use <CFIF =
Var is not "")?  Where Var is the variable in question that is from a =
form.

What is the proper syntax?  I looked in the Ben Forta CF book and there =
is no mention of this.

Please help...



------=_NextPart_000_0032_01BFD909.54A70BF0
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3017.2400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>When using CFIF and using a variable =
from a form is=20
it better to refer to the variable using ex:&nbsp; &lt;CFIF Form.Var is =
not=20
""&gt;&nbsp; or can I use &lt;CFIF Var is not "")?&nbsp; Where Var is =
the=20
variable in question that is from a form.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>What is the proper syntax?&nbsp; I =
looked in the=20
Ben Forta CF book and there is no mention of this.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Please help...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</DIV></FONT></BODY></HTML>

------=_NextPart_000_0032_01BFD909.54A70BF0--

----------------------------------------------------------------------------
--
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.

------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to