Re: CFC required arguments

2004-12-01 Thread Barney Boisvert
I usually want to know if the argument was passed, not if the argument
is the default value.  With a default value, that value necessarily
has to be a legal value for the argument.  Therefore there's no way to
tell if it was omitted or if the default value was explicitly passed.

Take this function for example:


  
  
...
  


The conditional will execute for both of these invocations:

test();
test("");

However, if I use this function:


  
  
...
  


The conditional will only execute for the former (where the argument
wasn't passed), and it'll treat "" just like it would treat any other
passed value.

cheers,
barneyb

On Wed, 1 Dec 2004 10:27:54 -0500, Sparrow-Hood, Walter
<[EMAIL PROTECTED]> wrote:
> Barney,
>I'm curious - why do you prefer structKeyExists() vs. setting
> default values?
> 
> Walt
> 
> 
> 
> -Original Message-
> From: Barney Boisvert [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, November 30, 2004 6:26 PM
> To: CF-Talk
> Subject: Re: CFC required arguments
> 
> If you use positional parameters, only parameters at the end can be
> left off.  However, you can use named parameters without using
> CFINVOKE:
> 
> 
> 
> I generally prefer to not specify a default for my option arguments,
> and then use structKeyExists() against the 'arguments' struct to check
> if they were passed.  Since we don't have method overloading in CF,
> optional parameters (and their associated conditionals) are a
> necessary evil.
> 
> cheers,
> barneyb
-- 
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/blog/

~|
Special thanks to the CF Community Suite Silver Sponsor - New Atlanta
http://www.newatlanta.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:185829
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


RE: CFC required arguments

2004-12-01 Thread Sparrow-Hood, Walter
Barney,
I'm curious - why do you prefer structKeyExists() vs. setting
default values?

Walt

-Original Message-
From: Barney Boisvert [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 30, 2004 6:26 PM
To: CF-Talk
Subject: Re: CFC required arguments

If you use positional parameters, only parameters at the end can be
left off.  However, you can use named parameters without using
CFINVOKE:



I generally prefer to not specify a default for my option arguments,
and then use structKeyExists() against the 'arguments' struct to check
if they were passed.  Since we don't have method overloading in CF,
optional parameters (and their associated conditionals) are a
necessary evil.

cheers,
barneyb

On Wed, 1 Dec 2004 10:20:27 +1100, Paul Wilson <[EMAIL PROTECTED]> wrote:
> I'm using createObject to invoke a CFC and one of the methods in the CFC
> takes a number of arguments, all numeric but not all required. In the
> CFC I have some conditional statements that do various things based on
> the arguments passed in.
>
> do this
>
> Firstly is it a good idea to do this in a CFC? And secondly, how can I
> pass is the only the arguments required .e.g.
>
> 
> The third argument is not required but this will throw an error. This
> situation doesn't arise when you use cfinvoke as you can simply miss out
> the cfinvokeargument tag.
>
> Thanks
>
--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/blog/



~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:185797
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


Re: CFC required arguments

2004-11-30 Thread Sean Corfield
On Wed, 1 Dec 2004 10:20:27 +1100, Paul Wilson <[EMAIL PROTECTED]> wrote:
> do this

If they are numeric arguments, you shouldn't have an empty string as
the default.

As other have hinted, specify required="false" but do not specify a
default= value.

Then you can test structKeyExists(arguments,'argname') to see whether
the arg has actually been supplied.
-- 
Sean A Corfield -- http://www.corfield.org/
Team Fusebox -- http://www.fusebox.org/
Breeze Me! -- http://www.corfield.org/breezeme
Got Gmail? -- I have 1 invite

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

~|
Special thanks to the CF Community Suite Silver Sponsor - New Atlanta
http://www.newatlanta.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:185765
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


RE: CFC required arguments

2004-11-30 Thread Taco Fleur
Another option is to use the argumentCollection, i.e.
obj.method( argumentCollection = structureContainingAllRequiredArguments )

Example:

variables.argumentCollection = structNew();
variables.argumentCollection.argument1 = form.argument1;
variables.argumentCollection.argument2 = url.argument2;
variables.argumentCollection.argument3 = variables.argument3;

obj.method( argumentCollection = variables.argumentCollection )

Off course if all arguments were in the form scope you could do
obj.method( argumentCollection = form )

-- 
Taco Fleur
Senior Web Systems Engineer
http://www.webassociates.com


-Original Message-
From: Paul Wilson [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 1 December 2004 9:20 AM
To: CF-Talk
Subject: CFC required arguments

I'm using createObject to invoke a CFC and one of the methods in the CFC
takes a number of arguments, all numeric but not all required. In the CFC I
have some conditional statements that do various things based on the
arguments passed in.

do this

 Firstly is it a good idea to do this in a CFC? And secondly, how can I pass
is the only the arguments required .e.g.

http://www.ruwebby.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:185761
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


Re: CFC required arguments

2004-11-30 Thread Spike
Another alternative is to use named arguments.



assuming your function is defined as:

 On Wed, 1 Dec 2004 10:20:27 +1100, Paul Wilson  wrote:
> 
> 
>>>
>>The third argument is not required but this will throw an error. This
>>situation doesn't arise when you use cfinvoke as you can simply miss out
>>the cfinvokeargument tag.
>>
> 
> 
> Generally in the CFC, I list the required arguments first and then the
> optional ones, primarily so I can use the obj.testmethod() syntax. 
> So, I'd suggest re-arranging the order of the arguments in your CFC. 
> This may require altering the calls to that method in other pages, of
> course.
> 
> Scott
> 

-- 


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

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

~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:185759
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


RE: CFC required arguments

2004-11-30 Thread Taco Fleur
By named parameters. 



Offcourse the argument name has to match the name in the method.

> do this
> Firstly is it a good idea to do this in a CFC?

Not sure what to answer here, I know in OOP it's a bad thing to have
switches and if's in a method.
Maybe your better off creating another method?
It's a shame we can't overload methods like in Java :-(

-- 
Taco Fleur
Senior Web Systems Engineer
http://www.webassociates.com


-Original Message-
From: Paul Wilson [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 1 December 2004 9:20 AM
To: CF-Talk
Subject: CFC required arguments

I'm using createObject to invoke a CFC and one of the methods in the CFC
takes a number of arguments, all numeric but not all required. In the CFC I
have some conditional statements that do various things based on the
arguments passed in.

do this

 Firstly is it a good idea to do this in a CFC? And secondly, how can I pass
is the only the arguments required .e.g.

http://www.newatlanta.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:185757
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


Re: CFC required arguments

2004-11-30 Thread Barney Boisvert
If you use positional parameters, only parameters at the end can be
left off.  However, you can use named parameters without using
CFINVOKE:



I generally prefer to not specify a default for my option arguments,
and then use structKeyExists() against the 'arguments' struct to check
if they were passed.  Since we don't have method overloading in CF,
optional parameters (and their associated conditionals) are a
necessary evil.

cheers,
barneyb

On Wed, 1 Dec 2004 10:20:27 +1100, Paul Wilson <[EMAIL PROTECTED]> wrote:
> I'm using createObject to invoke a CFC and one of the methods in the CFC
> takes a number of arguments, all numeric but not all required. In the
> CFC I have some conditional statements that do various things based on
> the arguments passed in.
> 
> do this
> 
> Firstly is it a good idea to do this in a CFC? And secondly, how can I
> pass is the only the arguments required .e.g.
> 
>  
> The third argument is not required but this will throw an error. This
> situation doesn't arise when you use cfinvoke as you can simply miss out
> the cfinvokeargument tag.
> 
> Thanks
> 
-- 
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/blog/

~|
Special thanks to the CF Community Suite Silver Sponsor - RUWebby
http://www.ruwebby.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:185755
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54


Re: CFC required arguments

2004-11-30 Thread Scott Brady
On Wed, 1 Dec 2004 10:20:27 +1100, Paul Wilson  wrote:

>  
> The third argument is not required but this will throw an error. This
> situation doesn't arise when you use cfinvoke as you can simply miss out
> the cfinvokeargument tag.
> 

Generally in the CFC, I list the required arguments first and then the
optional ones, primarily so I can use the obj.testmethod() syntax. 
So, I'd suggest re-arranging the order of the arguments in your CFC. 
This may require altering the calls to that method in other pages, of
course.

Scott

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

~|
Special thanks to the CF Community Suite Silver Sponsor - RUWebby
http://www.ruwebby.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:185754
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54