Re: CFParam vs. IsDefined

2010-09-04 Thread Scott Brady

On Wed, Sep 1, 2010 at 9:50 AM, Russ Michaels r...@michaels.me.uk wrote:


 defo better to make sure they are defined.
 Also using isDefined() is also bad as this search every single scope for
 your variable and is thus quite slow and can potentially cause timeouts.
 Much better to use StructKeyExists() and only test the scope your variable
 is in.


I'm not a fan of isDefined() [to put it mildly], but according to an
engineer from Adobe at MAX in 2008, there's no performance difference
between cfparam and isdefined (at least with CF9, if not earlier versions).

I just think it's sloppy programming to have to use it. :)

Scott
-- 
-
Scott Brady
http://www.scottbrady.net/


~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336827
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-04 Thread Scott Brady

It's working for me in cftags, using CFEclipse on the Mac (where it appears
to be CTRL-. [that's control and period] ).

I've never seen that feature before, so I'm going to try to start using it.

Scott

On Thu, Sep 2, 2010 at 4:32 AM, Andrew Scott andr...@andyscott.id.auwrote:


 Ok it works in cfscript but not in cftags syntax.

 Regards,
 Andrew Scott
 http://www.andyscott.id.au/


  -Original Message-
  From: Peter Boughton [mailto:bought...@gmail.com]
  Sent: Thursday, 2 September 2010 8:26 PM
  To: cf-talk
  Subject: Re: CFParam vs. IsDefined
 
 
  Hmmm, maybe they've changed the default.
 
  Goto WindowsPreferences and type keys in the filter box.
 
  That should bring the key binding panel, type word in that.
 
  Look for Word Completion option(s) and it'll list what the binding is.
 
  If it still doesn't work, check the When value - I've got one Editing
 Text
  and one In Windows.
 
  ~~
  ~~~|
  Order the Adobe Coldfusion Anthology now!
  http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-
  Dinowitz/dp/1430272155/?tag=houseoffusion
  Archive: http://www.houseoffusion.com/groups/cf-
  talk/message.cfm/messageid:336754
  Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
  Unsubscribe: http://www.houseoffusion.com/groups/cf-
  talk/unsubscribe.cfm


 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336828
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-02 Thread Peter Boughton

 That coupled with StructKeyExists is a pain to type!

Why on earth would you *type* it!?

This is exactly why your IDE has Word Completion, Snippets and Templates!

Str then Alt-/ completes word to StructKeyExists
(press Alt-/ again to cycle through other commonly used words)

ske then Ctrl-J snippet for StructKeyExists([cursor])

skel then Ctrl-Space,Enter to select a template:
StructKeyExists([Struct],'[Value]') AND Len([Struct].[Value])


(All this stuff is one of the things I keep meaning to write a full blog 
article on... if anyone is interested let me know and I'll try getting to it 
sooner, and post details here once done.) 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336748
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-02 Thread Peter Boughton

Oh, just to point out, ske and skel are custom ones I've created. They're not 
default commands.

Shortcut keys may vary too. 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336749
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


RE: CFParam vs. IsDefined

2010-09-02 Thread Andrew Scott

This must be a CFEclipse thing as CFBuilder is CTRL-SPACE

Regards,
Andrew Scott
http://www.andyscott.id.au/


 -Original Message-
 From: Peter Boughton [mailto:bought...@gmail.com]
 Sent: Thursday, 2 September 2010 7:01 PM
 To: cf-talk
 Subject: Re: CFParam vs. IsDefined
 
 
  That coupled with StructKeyExists is a pain to type!
 
 Why on earth would you *type* it!?
 
 This is exactly why your IDE has Word Completion, Snippets and Templates!
 
 Str then Alt-/ completes word to StructKeyExists (press Alt-/ again
to
 cycle through other commonly used words)
 
 ske then Ctrl-J snippet for StructKeyExists([cursor])
 
 skel then Ctrl-Space,Enter to select a template:
 StructKeyExists([Struct],'[Value]') AND Len([Struct].[Value])
 
 
 (All this stuff is one of the things I keep meaning to write a full blog
article
 on... if anyone is interested let me know and I'll try getting to it
sooner, and
 post details here once done.)
 
 ~~
 ~~~|
 Order the Adobe Coldfusion Anthology now!
 http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-
 Dinowitz/dp/1430272155/?tag=houseoffusion
 Archive: http://www.houseoffusion.com/groups/cf-
 talk/message.cfm/messageid:336748
 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
 Unsubscribe: http://www.houseoffusion.com/groups/cf-
 talk/unsubscribe.cfm


~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336750
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-02 Thread Peter Boughton

This must be a CFEclipse thing as CFBuilder is CTRL-SPACE

That's code completion. Word completion is faster (when you know what you want).

These are all Eclipse things (and will exist in any other IDE worth using), so 
available for both CFEclipse and CFBuilder. 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336751
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


RE: CFParam vs. IsDefined

2010-09-02 Thread Andrew Scott

Well that's interesting then because this Alt-/ doesn't work in my
CFBuilder installation.

Regards,
Andrew Scott
http://www.andyscott.id.au/


 -Original Message-
 From: Peter Boughton [mailto:bought...@gmail.com]
 Sent: Thursday, 2 September 2010 7:57 PM
 To: cf-talk
 Subject: Re: CFParam vs. IsDefined
 
 
 This must be a CFEclipse thing as CFBuilder is CTRL-SPACE
 
 That's code completion. Word completion is faster (when you know what
 you want).
 
 These are all Eclipse things (and will exist in any other IDE worth
using), so
 available for both CFEclipse and CFBuilder.


~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336752
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-02 Thread Michael Grant

I'm very interested. I just started using Aptana (coming from Homesite+) and
I really really want to speed up my dev to where I was at with HS+.
I'd love some more hotkey and snippet info.


On Thu, Sep 2, 2010 at 5:00 AM, Peter Boughton bought...@gmail.com wrote:


  That coupled with StructKeyExists is a pain to type!

 Why on earth would you *type* it!?

 This is exactly why your IDE has Word Completion, Snippets and Templates!

 Str then Alt-/ completes word to StructKeyExists
 (press Alt-/ again to cycle through other commonly used words)

 ske then Ctrl-J snippet for StructKeyExists([cursor])

 skel then Ctrl-Space,Enter to select a template:
 StructKeyExists([Struct],'[Value]') AND Len([Struct].[Value])


 (All this stuff is one of the things I keep meaning to write a full blog
 article on... if anyone is interested let me know and I'll try getting to it
 sooner, and post details here once done.)

 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336753
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-02 Thread Peter Boughton

Hmmm, maybe they've changed the default.

Goto WindowsPreferences and type keys in the filter box.

That should bring the key binding panel, type word in that.

Look for Word Completion option(s) and it'll list what the binding is.

If it still doesn't work, check the When value - I've got one Editing Text 
and one In Windows. 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336754
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


RE: CFParam vs. IsDefined

2010-09-02 Thread Andrew Scott

Ok it works in cfscript but not in cftags syntax.

Regards,
Andrew Scott
http://www.andyscott.id.au/


 -Original Message-
 From: Peter Boughton [mailto:bought...@gmail.com]
 Sent: Thursday, 2 September 2010 8:26 PM
 To: cf-talk
 Subject: Re: CFParam vs. IsDefined
 
 
 Hmmm, maybe they've changed the default.
 
 Goto WindowsPreferences and type keys in the filter box.
 
 That should bring the key binding panel, type word in that.
 
 Look for Word Completion option(s) and it'll list what the binding is.
 
 If it still doesn't work, check the When value - I've got one Editing
Text
 and one In Windows.
 
 ~~
 ~~~|
 Order the Adobe Coldfusion Anthology now!
 http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-
 Dinowitz/dp/1430272155/?tag=houseoffusion
 Archive: http://www.houseoffusion.com/groups/cf-
 talk/message.cfm/messageid:336754
 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
 Unsubscribe: http://www.houseoffusion.com/groups/cf-
 talk/unsubscribe.cfm


~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336755
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-02 Thread Rick Root

On Thu, Sep 2, 2010 at 5:00 AM, Peter Boughton bought...@gmail.com wrote:

 That coupled with StructKeyExists is a pain to type!

 Why on earth would you *type* it!?

vi doesn't do code completion?  lol

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336756
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-02 Thread Steve Lichtenberg

Yes it does :-).  In .virc set up aliases for anuything you want.  use them
in update mode not insert mode.

--S
  ^

On Thu, Sep 2, 2010 at 8:16 AM, Rick Root rick.r...@gmail.com wrote:


 On Thu, Sep 2, 2010 at 5:00 AM, Peter Boughton bought...@gmail.com
 wrote:
 
  That coupled with StructKeyExists is a pain to type!
 
  Why on earth would you *type* it!?

 vi doesn't do code completion?  lol

 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336757
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-02 Thread Rick Root

On Thu, Sep 2, 2010 at 8:23 AM, Steve Lichtenberg
steve.lichtenb...@gmail.com wrote:

 Yes it does :-).  In .virc set up aliases for anuything you want.  use them
 in update mode not insert mode.

touche' 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336759
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-02 Thread Claude Schnéegans

  Also using isDefined() is also bad as this search every single scope for 
your variable

CFPARAM will also search for the variable exactly the same way in order to 
create it if it does not exist.
What's the big differrence?

  and can potentially cause timeouts.

Wow! Where do you hide your variables so it takes so long to find them?

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336763
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


RE: CFParam vs. IsDefined

2010-09-01 Thread DURETTE, STEVEN J (ATTASIAIT)

Using your way ensures that any variables that you are using already
exist.

I was always taught that I should define my variables before I use them
in code (my ancient programming college courses).  So, I tend to follow
your method.

Also, from a security stand, you should already know what should be
coming into your page. If it isn't there then something went wrong. And
if you didn't define it and it is there you should be ignoring it.

Steve

-Original Message-
From: Michael Grant [mailto:mgr...@modus.bz] 
Sent: Wednesday, September 01, 2010 11:36 AM
To: cf-talk
Subject: CFParam vs. IsDefined


I prefer to CFParam my vars with a default value of a zero len string or
a 0
for numeric values. Then I skip the isdefined and just test against the
value. Well recently someone I know said that it's better to test if
it's
defined. Is there a pro or con to doing it my way vs. IsDefined ?

Thanks.




~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336711
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread Dave Watts

 I prefer to CFParam my vars with a default value of a zero len string or a 0
 for numeric values. Then I skip the isdefined and just test against the
 value. Well recently someone I know said that it's better to test if it's
 defined. Is there a pro or con to doing it my way vs. IsDefined ?

No, this is a matter of personal preference really. My preference
tends to align with yours for the reasons that Steven mentioned, but
that's more of a documentation issue than anything else.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336712
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread Russ Michaels

defo better to make sure they are defined.
Also using isDefined() is also bad as this search every single scope for
your variable and is thus quite slow and can potentially cause timeouts.
Much better to use StructKeyExists() and only test the scope your variable
is in.

--
Russ Michaels
www.cfmldeveloper.com
Supporting the cf community since 1999
FREE ColdFusion/Railo hosting for developers.


On Wed, Sep 1, 2010 at 4:40 PM, DURETTE, STEVEN J (ATTASIAIT) 
sd1...@att.com wrote:


 Using your way ensures that any variables that you are using already
 exist.

 I was always taught that I should define my variables before I use them
 in code (my ancient programming college courses).  So, I tend to follow
 your method.

 Also, from a security stand, you should already know what should be
 coming into your page. If it isn't there then something went wrong. And
 if you didn't define it and it is there you should be ignoring it.

 Steve

 -Original Message-
 From: Michael Grant [mailto:mgr...@modus.bz]
 Sent: Wednesday, September 01, 2010 11:36 AM
 To: cf-talk
 Subject: CFParam vs. IsDefined


 I prefer to CFParam my vars with a default value of a zero len string or
 a 0
 for numeric values. Then I skip the isdefined and just test against the
 value. Well recently someone I know said that it's better to test if
 it's
 defined. Is there a pro or con to doing it my way vs. IsDefined ?

 Thanks.




 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336713
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread John M Bliss

FWIW, the following two tickcounts are nearly identical on my localhost so
the reason to use one over the other (cfparam versus isdefined/set) is
likely not due to performance...

cfset starttick = getTickCount()

cfloop index=i from=1 to=1
cfparam default=#i# name=variables.var#i#
/cfloop

cfoutput#Evaluate(getTickCount() - starttick)#/cfoutput

cfset starttick = getTickCount()

cfloop index=i from=1 to=1
cfif not IsDefined(variables.anothervar  i)
cfset SetVariable(variables.anothervar  i, i)
/cfif
/cfloop

cfoutput#Evaluate(getTickCount() - starttick)#/cfoutput

On Wed, Sep 1, 2010 at 10:50 AM, Russ Michaels r...@michaels.me.uk wrote:


 defo better to make sure they are defined.
 Also using isDefined() is also bad as this search every single scope for
 your variable and is thus quite slow and can potentially cause timeouts.
 Much better to use StructKeyExists() and only test the scope your variable
 is in.

 --
 Russ Michaels
 www.cfmldeveloper.com
 Supporting the cf community since 1999
 FREE ColdFusion/Railo hosting for developers.


 On Wed, Sep 1, 2010 at 4:40 PM, DURETTE, STEVEN J (ATTASIAIT) 
 sd1...@att.com wrote:

 
  Using your way ensures that any variables that you are using already
  exist.
 
  I was always taught that I should define my variables before I use them
  in code (my ancient programming college courses).  So, I tend to follow
  your method.
 
  Also, from a security stand, you should already know what should be
  coming into your page. If it isn't there then something went wrong. And
  if you didn't define it and it is there you should be ignoring it.
 
  Steve
 
  -Original Message-
  From: Michael Grant [mailto:mgr...@modus.bz]
  Sent: Wednesday, September 01, 2010 11:36 AM
  To: cf-talk
  Subject: CFParam vs. IsDefined
 
 
  I prefer to CFParam my vars with a default value of a zero len string or
  a 0
  for numeric values. Then I skip the isdefined and just test against the
  value. Well recently someone I know said that it's better to test if
  it's
  defined. Is there a pro or con to doing it my way vs. IsDefined ?
 
  Thanks.
 
 
 
 
 

 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336714
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


RE: CFParam vs. IsDefined

2010-09-01 Thread Mark A. Kruger

Russ,

You are correct about that - but it's not typically a performance problem in
my view. More of a buggy/security type problem :)

-Mark

Mark A. Kruger, MCSE, CFG
(402) 408-3733 ext 105
Skype: markakruger
www.cfwebtools.com
www.coldfusionmuse.com
www.necfug.com



-Original Message-
From: Russ Michaels [mailto:r...@michaels.me.uk] 
Sent: Wednesday, September 01, 2010 10:51 AM
To: cf-talk
Subject: Re: CFParam vs. IsDefined


defo better to make sure they are defined.
Also using isDefined() is also bad as this search every single scope for
your variable and is thus quite slow and can potentially cause timeouts.
Much better to use StructKeyExists() and only test the scope your variable
is in.

--
Russ Michaels
www.cfmldeveloper.com
Supporting the cf community since 1999
FREE ColdFusion/Railo hosting for developers.


On Wed, Sep 1, 2010 at 4:40 PM, DURETTE, STEVEN J (ATTASIAIT) 
sd1...@att.com wrote:


 Using your way ensures that any variables that you are using already
 exist.

 I was always taught that I should define my variables before I use them
 in code (my ancient programming college courses).  So, I tend to follow
 your method.

 Also, from a security stand, you should already know what should be
 coming into your page. If it isn't there then something went wrong. And
 if you didn't define it and it is there you should be ignoring it.

 Steve

 -Original Message-
 From: Michael Grant [mailto:mgr...@modus.bz]
 Sent: Wednesday, September 01, 2010 11:36 AM
 To: cf-talk
 Subject: CFParam vs. IsDefined


 I prefer to CFParam my vars with a default value of a zero len string or
 a 0
 for numeric values. Then I skip the isdefined and just test against the
 value. Well recently someone I know said that it's better to test if
 it's
 defined. Is there a pro or con to doing it my way vs. IsDefined ?

 Thanks.




 



~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336715
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread Russ Michaels

it depends how many vars you have in each scope.
If you have barely any then the search will be quick.
If you have a complex app with hundreds of vars then the result will of
course be different, especially if they are complex structs.

There is also the fact that isdefined() will find the variable in ANY scope,
which may not be the one you want.

e.g.
isDefined('myvar')
would find

variables.myvar
cookie.myvar
session.myvar

etc
so if you are actually looking for myvar only in the form scope then this
could cause you issues, you also need to remember that dot notation means
nothing to isdefined(), so isDefined('form.myvar') could also find

session.form.myvar
url.form.myvar
cookie.form.var

etc

On Wed, Sep 1, 2010 at 4:56 PM, Mark A. Kruger mkru...@cfwebtools.comwrote:


 Russ,

 You are correct about that - but it's not typically a performance problem
 in
 my view. More of a buggy/security type problem :)

 -Mark

 Mark A. Kruger, MCSE, CFG
 (402) 408-3733 ext 105
 Skype: markakruger
 www.cfwebtools.com
 www.coldfusionmuse.com
 www.necfug.com



 -Original Message-
 From: Russ Michaels [mailto:r...@michaels.me.uk]
 Sent: Wednesday, September 01, 2010 10:51 AM
 To: cf-talk
 Subject: Re: CFParam vs. IsDefined


 defo better to make sure they are defined.
 Also using isDefined() is also bad as this search every single scope for
 your variable and is thus quite slow and can potentially cause timeouts.
 Much better to use StructKeyExists() and only test the scope your variable
 is in.

 --
 Russ Michaels
 www.cfmldeveloper.com
 Supporting the cf community since 1999
 FREE ColdFusion/Railo hosting for developers.


 On Wed, Sep 1, 2010 at 4:40 PM, DURETTE, STEVEN J (ATTASIAIT) 
 sd1...@att.com wrote:

 
  Using your way ensures that any variables that you are using already
  exist.
 
  I was always taught that I should define my variables before I use them
  in code (my ancient programming college courses).  So, I tend to follow
  your method.
 
  Also, from a security stand, you should already know what should be
  coming into your page. If it isn't there then something went wrong. And
  if you didn't define it and it is there you should be ignoring it.
 
  Steve
 
  -Original Message-
  From: Michael Grant [mailto:mgr...@modus.bz]
  Sent: Wednesday, September 01, 2010 11:36 AM
  To: cf-talk
  Subject: CFParam vs. IsDefined
 
 
  I prefer to CFParam my vars with a default value of a zero len string or
  a 0
  for numeric values. Then I skip the isdefined and just test against the
  value. Well recently someone I know said that it's better to test if
  it's
  defined. Is there a pro or con to doing it my way vs. IsDefined ?
 
  Thanks.
 
 
 
 
 



 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336716
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


RE: CFParam vs. IsDefined

2010-09-01 Thread Andy Matthews

One reason to use IsDefined over StructKeyExists is when you don't know if
one of the child structures exists.

For example, in our control app, we assign permissions to our users like so:

SESSION.p -- struct, always exists
SESSION.p.nav -- struct, exists if the user has at least one perm in this
set 
SESSION.p.nav.SOMEPERMISSION !-- bool, only exists if this user has this
perm

So you can see that if we wanted to check if someone had SOMEPERMISSION we'd
have to do some dancing around to use StructKeyExists. Instead we just say
IsDefined('SESSION.p.nav.SOMEPERMISSION') and we're done.

Admittedly we could probably do this more efficiently by having all perms as
keys inside a perms struct, but cest la vie.


andy


-Original Message-
From: Russ Michaels [mailto:r...@michaels.me.uk] 
Sent: Wednesday, September 01, 2010 10:51 AM
To: cf-talk
Subject: Re: CFParam vs. IsDefined


defo better to make sure they are defined.
Also using isDefined() is also bad as this search every single scope for
your variable and is thus quite slow and can potentially cause timeouts.
Much better to use StructKeyExists() and only test the scope your variable
is in.

--
Russ Michaels
www.cfmldeveloper.com
Supporting the cf community since 1999
FREE ColdFusion/Railo hosting for developers.


On Wed, Sep 1, 2010 at 4:40 PM, DURETTE, STEVEN J (ATTASIAIT) 
sd1...@att.com wrote:


 Using your way ensures that any variables that you are using already 
 exist.

 I was always taught that I should define my variables before I use 
 them in code (my ancient programming college courses).  So, I tend to 
 follow your method.

 Also, from a security stand, you should already know what should be 
 coming into your page. If it isn't there then something went wrong. 
 And if you didn't define it and it is there you should be ignoring it.

 Steve

 -Original Message-
 From: Michael Grant [mailto:mgr...@modus.bz]
 Sent: Wednesday, September 01, 2010 11:36 AM
 To: cf-talk
 Subject: CFParam vs. IsDefined


 I prefer to CFParam my vars with a default value of a zero len string 
 or a 0 for numeric values. Then I skip the isdefined and just test 
 against the value. Well recently someone I know said that it's better 
 to test if it's defined. Is there a pro or con to doing it my way vs. 
 IsDefined ?

 Thanks.




 



~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336717
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread John M Bliss

 dot notation means nothing to isdefined()

Um, really?  The following returns NO for me:

cfset variables.myvar = 1

cfoutput#IsDefined(url.myvar)#/cfoutput


On Wed, Sep 1, 2010 at 11:16 AM, Russ Michaels r...@michaels.me.uk wrote:


 it depends how many vars you have in each scope.
 If you have barely any then the search will be quick.
 If you have a complex app with hundreds of vars then the result will of
 course be different, especially if they are complex structs.

 There is also the fact that isdefined() will find the variable in ANY
 scope,
 which may not be the one you want.

 e.g.
 isDefined('myvar')
 would find

 variables.myvar
 cookie.myvar
 session.myvar

 etc
 so if you are actually looking for myvar only in the form scope then this
 could cause you issues, you also need to remember that dot notation means
 nothing to isdefined(), so isDefined('form.myvar') could also find

 session.form.myvar
 url.form.myvar
 cookie.form.var

 etc

 On Wed, Sep 1, 2010 at 4:56 PM, Mark A. Kruger mkru...@cfwebtools.com
 wrote:

 
  Russ,
 
  You are correct about that - but it's not typically a performance problem
  in
  my view. More of a buggy/security type problem :)
 
  -Mark
 
  Mark A. Kruger, MCSE, CFG
  (402) 408-3733 ext 105
  Skype: markakruger
  www.cfwebtools.com
  www.coldfusionmuse.com
  www.necfug.com
 
 
 
  -Original Message-
  From: Russ Michaels [mailto:r...@michaels.me.uk]
  Sent: Wednesday, September 01, 2010 10:51 AM
  To: cf-talk
  Subject: Re: CFParam vs. IsDefined
 
 
  defo better to make sure they are defined.
  Also using isDefined() is also bad as this search every single scope for
  your variable and is thus quite slow and can potentially cause timeouts.
  Much better to use StructKeyExists() and only test the scope your
 variable
  is in.
 
  --
  Russ Michaels
  www.cfmldeveloper.com
  Supporting the cf community since 1999
  FREE ColdFusion/Railo hosting for developers.
 
 
  On Wed, Sep 1, 2010 at 4:40 PM, DURETTE, STEVEN J (ATTASIAIT) 
  sd1...@att.com wrote:
 
  
   Using your way ensures that any variables that you are using already
   exist.
  
   I was always taught that I should define my variables before I use them
   in code (my ancient programming college courses).  So, I tend to follow
   your method.
  
   Also, from a security stand, you should already know what should be
   coming into your page. If it isn't there then something went wrong. And
   if you didn't define it and it is there you should be ignoring it.
  
   Steve
  
   -Original Message-
   From: Michael Grant [mailto:mgr...@modus.bz]
   Sent: Wednesday, September 01, 2010 11:36 AM
   To: cf-talk
   Subject: CFParam vs. IsDefined
  
  
   I prefer to CFParam my vars with a default value of a zero len string
 or
   a 0
   for numeric values. Then I skip the isdefined and just test against the
   value. Well recently someone I know said that it's better to test if
   it's
   defined. Is there a pro or con to doing it my way vs. IsDefined ?
  
   Thanks.
  
  
  
  
  
 
 
 
 

 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336718
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread Sean Corfield

On Wed, Sep 1, 2010 at 8:54 AM, John M Bliss bliss.j...@gmail.com wrote:
 cfloop index=i from=1 to=1
 cfif not IsDefined(variables.anothervar  i)
 cfset SetVariable(variables.anothervar  i, i)
 /cfif
 /cfloop

Try that with cfset variables[anothervar  i] = i / - I suspect
setVariable() is slowing that down.

 cfoutput#Evaluate(getTickCount() - starttick)#/cfoutput

You don't need evaluate() here BTW.

In general, micro-benchmarks like this aren't really useful. For
example, you're generating lots of whitespace here so you'd do better
to wrap the loops in cfsilent or write them in cfscript. There are
all sorts of variable factors in code like this.
-- 
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

If you're not annoying somebody, you're not really alive.
-- Margaret Atwood

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336719
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread John M Bliss

Nevermind.  Misread your post.

On Wed, Sep 1, 2010 at 11:24 AM, John M Bliss bliss.j...@gmail.com wrote:

  dot notation means nothing to isdefined()

 Um, really?  The following returns NO for me:

 cfset variables.myvar = 1

 cfoutput#IsDefined(url.myvar)#/cfoutput


 On Wed, Sep 1, 2010 at 11:16 AM, Russ Michaels r...@michaels.me.ukwrote:


 it depends how many vars you have in each scope.
 If you have barely any then the search will be quick.
 If you have a complex app with hundreds of vars then the result will of
 course be different, especially if they are complex structs.

 There is also the fact that isdefined() will find the variable in ANY
 scope,
 which may not be the one you want.

 e.g.
 isDefined('myvar')
 would find

 variables.myvar
 cookie.myvar
 session.myvar

 etc
 so if you are actually looking for myvar only in the form scope then this
 could cause you issues, you also need to remember that dot notation means
 nothing to isdefined(), so isDefined('form.myvar') could also find

 session.form.myvar
 url.form.myvar
 cookie.form.var

 etc

 On Wed, Sep 1, 2010 at 4:56 PM, Mark A. Kruger mkru...@cfwebtools.com
 wrote:

 
  Russ,
 
  You are correct about that - but it's not typically a performance
 problem
  in
  my view. More of a buggy/security type problem :)
 
  -Mark
 
  Mark A. Kruger, MCSE, CFG
  (402) 408-3733 ext 105
  Skype: markakruger
  www.cfwebtools.com
  www.coldfusionmuse.com
  www.necfug.com
 
 
 
  -Original Message-
  From: Russ Michaels [mailto:r...@michaels.me.uk]
  Sent: Wednesday, September 01, 2010 10:51 AM
  To: cf-talk
  Subject: Re: CFParam vs. IsDefined
 
 
  defo better to make sure they are defined.
  Also using isDefined() is also bad as this search every single scope for
  your variable and is thus quite slow and can potentially cause timeouts.
  Much better to use StructKeyExists() and only test the scope your
 variable
  is in.
 
  --
  Russ Michaels
  www.cfmldeveloper.com
  Supporting the cf community since 1999
  FREE ColdFusion/Railo hosting for developers.
 
 
  On Wed, Sep 1, 2010 at 4:40 PM, DURETTE, STEVEN J (ATTASIAIT) 
  sd1...@att.com wrote:
 
  
   Using your way ensures that any variables that you are using already
   exist.
  
   I was always taught that I should define my variables before I use
 them
   in code (my ancient programming college courses).  So, I tend to
 follow
   your method.
  
   Also, from a security stand, you should already know what should be
   coming into your page. If it isn't there then something went wrong.
 And
   if you didn't define it and it is there you should be ignoring it.
  
   Steve
  
   -Original Message-
   From: Michael Grant [mailto:mgr...@modus.bz]
   Sent: Wednesday, September 01, 2010 11:36 AM
   To: cf-talk
   Subject: CFParam vs. IsDefined
  
  
   I prefer to CFParam my vars with a default value of a zero len string
 or
   a 0
   for numeric values. Then I skip the isdefined and just test against
 the
   value. Well recently someone I know said that it's better to test if
   it's
   defined. Is there a pro or con to doing it my way vs. IsDefined ?
  
   Thanks.
  
  
  
  
  
 
 
 
 

 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336720
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread Roger Austin

 Michael Grant mgr...@modus.bz wrote: 
 
 I prefer to CFParam my vars with a default value of a zero len string or a 0
 for numeric values. Then I skip the isdefined and just test against the
 value. Well recently someone I know said that it's better to test if it's
 defined. Is there a pro or con to doing it my way vs. IsDefined ?

I would use cfparam out of convenience and flow. If you use the incoming 
parameter several times, you don't have to test it but once with cfparam.
I'm lazy.
--
LinkedIn: http://www.linkedin.com/pub/roger-austin/8/a4/60
Twitter:  http://twitter.com/RogerTheGeek
Blog: http://rogerthegeek.wordpress.com/
http://www.misshunt.com/ Home of the Clean/Dirty Magnet


~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336721
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread Russ Michaels

of course as you are checking for url.myvar which doesn't exist as you
created variables.myvar not url.myvar.



On Wed, Sep 1, 2010 at 5:24 PM, John M Bliss bliss.j...@gmail.com wrote:


  dot notation means nothing to isdefined()

 Um, really?  The following returns NO for me:

 cfset variables.myvar = 1

 cfoutput#IsDefined(url.myvar)#/cfoutput


 On Wed, Sep 1, 2010 at 11:16 AM, Russ Michaels r...@michaels.me.uk
 wrote:

 
  it depends how many vars you have in each scope.
  If you have barely any then the search will be quick.
  If you have a complex app with hundreds of vars then the result will of
  course be different, especially if they are complex structs.
 
  There is also the fact that isdefined() will find the variable in ANY
  scope,
  which may not be the one you want.
 
  e.g.
  isDefined('myvar')
  would find
 
  variables.myvar
  cookie.myvar
  session.myvar
 
  etc
  so if you are actually looking for myvar only in the form scope then this
  could cause you issues, you also need to remember that dot notation means
  nothing to isdefined(), so isDefined('form.myvar') could also find
 
  session.form.myvar
  url.form.myvar
  cookie.form.var
 
  etc
 
  On Wed, Sep 1, 2010 at 4:56 PM, Mark A. Kruger mkru...@cfwebtools.com
  wrote:
 
  
   Russ,
  
   You are correct about that - but it's not typically a performance
 problem
   in
   my view. More of a buggy/security type problem :)
  
   -Mark
  
   Mark A. Kruger, MCSE, CFG
   (402) 408-3733 ext 105
   Skype: markakruger
   www.cfwebtools.com
   www.coldfusionmuse.com
   www.necfug.com
  
  
  
   -Original Message-
   From: Russ Michaels [mailto:r...@michaels.me.uk]
   Sent: Wednesday, September 01, 2010 10:51 AM
   To: cf-talk
   Subject: Re: CFParam vs. IsDefined
  
  
   defo better to make sure they are defined.
   Also using isDefined() is also bad as this search every single scope
 for
   your variable and is thus quite slow and can potentially cause
 timeouts.
   Much better to use StructKeyExists() and only test the scope your
  variable
   is in.
  
   --
   Russ Michaels
   www.cfmldeveloper.com
   Supporting the cf community since 1999
   FREE ColdFusion/Railo hosting for developers.
  
  
   On Wed, Sep 1, 2010 at 4:40 PM, DURETTE, STEVEN J (ATTASIAIT) 
   sd1...@att.com wrote:
  
   
Using your way ensures that any variables that you are using already
exist.
   
I was always taught that I should define my variables before I use
 them
in code (my ancient programming college courses).  So, I tend to
 follow
your method.
   
Also, from a security stand, you should already know what should be
coming into your page. If it isn't there then something went wrong.
 And
if you didn't define it and it is there you should be ignoring it.
   
Steve
   
-Original Message-
From: Michael Grant [mailto:mgr...@modus.bz]
Sent: Wednesday, September 01, 2010 11:36 AM
To: cf-talk
Subject: CFParam vs. IsDefined
   
   
I prefer to CFParam my vars with a default value of a zero len string
  or
a 0
for numeric values. Then I skip the isdefined and just test against
 the
value. Well recently someone I know said that it's better to test if
it's
defined. Is there a pro or con to doing it my way vs. IsDefined ?
   
Thanks.
   
   
   
   
   
  
  
  
  
 
 

 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336727
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread Peter Boughton

I prefer to CFParam my vars with a default value of a zero len string or a 0
for numeric values. Then I skip the isdefined and just test against the
value. Well recently someone I know said that it's better to test if it's
defined. Is there a pro or con to doing it my way vs. IsDefined ?

There is a difference between a value being undefined, and a value being zero.


Consider the following (contrived) example:

cffunction name=convertToKelvin returntype=Numeric output=false
cfargument name=Celsius   type=Numeric default=0 /
cfargument name=Farenheit type=Numeric default=0 /

cfif Arguments.Celsius NEQ 0
...
cfelseif Arguments.Farenheight NEQ 0
... 
cfelse
cfthrow message=Invalid arguments/
/cfif

/cffunction


vs


cffunction name=convertToKelvin returntype=Numeric output=false
cfargument name=Celsius   type=Numeric required=false /
cfargument name=Farenheit type=Numeric required=false /

cfif isDefined('Arguments.Celsius')
...
cfelseif isDefined('Arguments.Farenheight')
... 
cfelse
cfthrow message=Invalid arguments/
/cfif

/cffunction

(Using cfargument/default is equiv to using cfparam/default.)

Unless you can say with certainty that blank/zero is identically equivalent to 
undefined, you should always check for existance (using either isDefined or 
structKeyExists as preferred) instead of setting a default. 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336728
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread David McGraw

The only general advantage I see is that you are reserving memory no matter 
what, even though it's not much, where as with the isDefined, your just 
checking, rather than reserving that memory.


I prefer to CFParam my vars with a default value of a zero len string or a 0
for numeric values. Then I skip the isdefined and just test against the
value. Well recently someone I know said that it's better to test if it's
defined. Is there a pro or con to doing it my way vs. IsDefined ?

Thanks.



~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336741
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread Rick Root

Personally I like to cfparam things that I know are supposed to
exist, and I will go both ways on page variables that may or may not
exist.

I prefer to param it and then test for a valid value than to test for
isDefined()

Ie...

cfparam name=someid default=
cfif someid eq   (or cfif len(someid) eq 0  )
   Holy Crap!cfabort
/cfif

Rick

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336743
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread Casey Dougall

On Wed, Sep 1, 2010 at 5:56 PM, Rick Root rick.r...@gmail.com wrote:


 Personally I like to cfparam things that I know are supposed to
 exist, and I will go both ways on page variables that may or may not
 exist.

 I prefer to param it and then test for a valid value than to test for
 isDefined()



Yup, and you can throw all of them at the top of the script.

I'm not saying there isn't times you need to use StructKeyExists.
Readability is by far my biggest goal, the faster I can read though a
script, the less hassles I have with it as a whole, and cfparam allows you
to use a built in function to assist in setting up page variables.

Not saying there arn't times you should use StuctKeyExists, but if it was a
param to begin with, you already know the default value; That coupled with
StructKeyExists is a pain to type!


~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336745
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: CFParam vs. IsDefined

2010-09-01 Thread Tony Bentley

A classic issue yesterday related to isDefined():

This worked perfectly:

cfscript
//pass boolean to determine if the given field is null in the
stored proc (1=submitted, 2=finalized)
if(arguments.status eq 1){
submitted = false;
finalized = true;
}
else if(arguments.status eq 2){
finalized = false;
submitted = true;
}
/cfscript
cfstoredproc datasource=#this.datasource#
procedure=prc_updateReportStatus
cfprocparam cfsqltype=CF_SQL_INTEGER value=#this.reportid#
cfprocparam cfsqltype=CF_SQL_INTEGER value=#this.userid#
null=#submitted#
cfprocparam cfsqltype=CF_SQL_INTEGER value=#this.userid#
null=#finalized#
cfprocresult name=qry
/cfstoredproc

This did not:

cfscript
//pass boolean to determine if the given field is null in the
stored proc (1=submitted, 2=finalized)
if(arguments.status eq 1){
submitted = true;
}
else if(arguments.status eq 2){
finalized = true;
}
/cfscript
cfstoredproc datasource=#this.datasource#
procedure=prc_updateReportStatus
cfprocparam cfsqltype=CF_SQL_INTEGER value=#this.reportid#
cfprocparam cfsqltype=CF_SQL_INTEGER value=#this.userid#
null=#isDefined('submitted')#
cfprocparam cfsqltype=CF_SQL_INTEGER value=#this.userid#
null=#isDefined('finalized')#
cfprocresult name=qry
/cfstoredproc

I ran a DB trace and both values were coming out as defined in the second
code.


~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336747
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm