RE: CF functions question
Thanks Dominic, I'd forgotten the cfreturn J -Original Message- From: Dominic Watson [mailto:[EMAIL PROTECTED] Sent: 03 March 2008 11:28 To: CF-Talk Subject: Re: CF functions question I would I would like to return the structure to the refering page, is this possible, please? Sure is: Function code: cffunction name=foo returntype=struct cfset stBar = StructNew() cfset stBar.bar = foo cfset stBar.foo = bar cfreturn stBar /cffunction Calling template: cfset stResult = foo() HTH Dominic -- Blog it up: http://fusion.dominicwatson.co.uk ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:301396 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: CF functions question
I would I would like to return the structure to the refering page, is this possible, please? Sure is: Function code: cffunction name=foo returntype=struct cfset stBar = StructNew() cfset stBar.bar = foo cfset stBar.foo = bar cfreturn stBar /cffunction Calling template: cfset stResult = foo() HTH Dominic -- Blog it up: http://fusion.dominicwatson.co.uk ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300303 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: CF functions question
Remember to var your variables! On Mon, Mar 3, 2008 at 4:27 AM, Dominic Watson [EMAIL PROTECTED] wrote: Function code: cffunction name=foo returntype=struct cfset stBar = StructNew() cfset stBar.bar = foo cfset stBar.foo = bar cfreturn stBar /cffunction should be: cffunction name=foo returntype=struct cfset var stBar = StructNew() cfset stBar.bar = foo cfset stBar.foo = bar cfreturn stBar /cffunction -- nathan strutz http://www.dopefly.com/ ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300319 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: CF functions question
To play Devil's advocate here-- other than standard coding habits, why would one need to var these variables? This function (in the example given) is called in the context of the current page and is not a method in any persisted component which could be servicing multiple requests. I would see the benefit, if it was called as: cfset stResult = application.persistent_component.foo(client.user_specific _input) But is there any benefit to the var in the example Dominic posted? I'm not saying anyone's wrong yet-- I just want to know if there was a good reason. Thanks. ~Brad -Original Message- From: Nathan Strutz [mailto:[EMAIL PROTECTED] Sent: Monday, March 03, 2008 8:59 AM To: CF-Talk Subject: Re: CF functions question Remember to var your variables! ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300329 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: CF functions question
No, you absolutely should var that variable, persistant component or UDF or whatever and I always var my function and method variables (just lapsed in this silly example). This other silly example demonstrates why (run in a single template): cffunction name=foo cfset i = 100 cfreturn 'bar' /cffunction cfoutput cfset i = 1 cfloop condition=i LT 10 cfset bar = foo() #i#br / cfset i = i + 1 /cfloop /cfoutput You'd expect the loop to loop 10 times but it doesn't. Var that variable in the function and it does. Dominic -- Blog it up: http://fusion.dominicwatson.co.uk ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300330 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: CF functions question
Fair enough. I had considered the case where variables in your function might overwrite other variables in the page, but had figured people should know better to have multiple variables on the same page with the same name. Of course, who's to say the UDF couldn't have been written by a different programmer and cfincluded in a library of other functions. Then all of a sudden it would be much easier to get unintentional overwriting of variables. Color me convinced. :) ~Brad -Original Message- From: Dominic Watson [mailto:[EMAIL PROTECTED] Sent: Monday, March 03, 2008 2:24 PM To: CF-Talk Subject: Re: CF functions question No, you absolutely should var that variable, persistant component or UDF or whatever and I always var my function and method variables (just lapsed in this silly example). This other silly example demonstrates why (run in a single template): cffunction name=foo cfset i = 100 cfreturn 'bar' /cffunction cfoutput cfset i = 1 cfloop condition=i LT 10 cfset bar = foo() #i#br / cfset i = i + 1 /cfloop /cfoutput You'd expect the loop to loop 10 times but it doesn't. Var that variable in the function and it does. Dominic ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300333 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: CF functions question
To play Devil's advocate here-- other than standard coding habits, why would one need to var these variables? This function (in the example given) is called in the context of the current page and is not a method in any persisted component which could be servicing multiple requests. The application of best practices doesn't always make a difference in any given case. The point of applying best practices is that you don't have to evaluate each case individually. That's why there are so few actual best practices! Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Training: Adobe/Google/Paperthin Certified Partners http://training.figleaf.com/ WebManiacs 2008: the ultimate conference for CF/Flex/AIR developers! http://www.webmaniacsconference.com/ ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300334 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: CF functions question
Dom, Great example -Original Message- From: Dominic Watson [mailto:[EMAIL PROTECTED] Sent: Monday, March 03, 2008 2:24 PM To: CF-Talk Subject: Re: CF functions question No, you absolutely should var that variable, persistant component or UDF or whatever and I always var my function and method variables (just lapsed in this silly example). This other silly example demonstrates why (run in a single template): cffunction name=foo cfset i = 100 cfreturn 'bar' /cffunction cfoutput cfset i = 1 cfloop condition=i LT 10 cfset bar = foo() #i#br / cfset i = i + 1 /cfloop /cfoutput You'd expect the loop to loop 10 times but it doesn't. Var that variable in the function and it does. Dominic -- Blog it up: http://fusion.dominicwatson.co.uk ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300335 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: CF functions question
Dom, Great example Lol thanks. I learned from experience and it was through exactly that (looping over an iterator and then calling a function that used the same throwaway variable name for its own loop iterator... server kept grinding to a halt for some reason :p)! -- Blog it up: http://fusion.dominicwatson.co.uk ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300337 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: CF functions question
I can appreciate that. I like a consistent coding style if for no other reason than to know what to expect when you are maintaining the code. Problem is, sometimes I have trouble distinguishing between people's best practices, and knee jerk reactions. That was why I asked-- to see if there was a valid reason, or if it was just the token response to any thread involving cf functions. Dominic's response was convincing enough for me though. ~Brad -Original Message- From: Dave Watts [mailto:[EMAIL PROTECTED] Sent: Monday, March 03, 2008 3:01 PM To: CF-Talk Subject: RE: CF functions question To play Devil's advocate here-- other than standard coding habits, why would one need to var these variables? This function (in the example given) is called in the context of the current page and is not a method in any persisted component which could be servicing multiple requests. The application of best practices doesn't always make a difference in any given case. The point of applying best practices is that you don't have to evaluate each case individually. That's why there are so few actual best practices! ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300338 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: CF functions question
I learned from experience Let me translate that: You learned the hard way. ;) I just got done pulling my hair out trying to update a variable that wasn't scoped. It was not being updated no matter what I did to it. EX: cfif NOT isdate(returningdate) cfset returningdate= Now() /cfif returningdate would return and empty string. It was only when I scoped it was able to manipulate it. Live and learn. On Mon, Mar 3, 2008 at 4:09 PM, Dominic Watson [EMAIL PROTECTED] wrote: Dom, Great example Lol thanks. I learned from experience and it was through exactly that (looping over an iterator and then calling a function that used the same throwaway variable name for its own loop iterator... server kept grinding to a halt for some reason :p)! -- Blog it up: http://fusion.dominicwatson.co.uk ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300342 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4