[cfaussie] Re: isDefined() bad?
I agree. I am currently the lead developer and architect for a rather large project with structures as complex as you have, Grant. I have been very strict with ensuring that the structures are initialised properly with sane default values as it saves a lot of heartache in the long run. I understand where you are comming from but all I can say is don't be lazy cause it will bite you on the arse later I do have some exceptions when a CFC is being loaded into the session scope to persist it along with the session data it relates to (I said that bit so Peter doesn't ask me why I don't just shove it in the application scope) then I do use isDefined and isSimpleValue to see if the CFC needs to be created and initialised. For anyone that is interested, we have a 30 Gig database and 70 Gigs of files to process in our application. Performance is a huge issue. Having said that we have been able to tune the database (Postgresql) so we can sub second response from tables with 150 million rows in them. Cheers, Simon On 05/06/07, Haikal Saadh [EMAIL PROTECTED] wrote: Seems to be 6 of one and 1/2 dozen of another... but if you initialise it properly in one place, and it saves you from doing the check in 2 or more places, you've come out ahead. grant wrote: @Dale: It throws. @Haikal: Good Point. It's that laziness again - setting up and maintaining defaults can be rather tiresome. On 05/06/07, *Haikal Saadh * [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Personally, I favour sane defaults rather than having to check for presence of variables all the time. And the bigger and more complicated your data structs get, I think having to check to see if a variable exists is a quick path to insanity. Side effect of eating too much spaghetti... grant wrote: Wow thanks for the response people. My question is really out of pure laziness - I have a huge struct that i need to check a key for - the actual key path is session.currentuser.currentreport.filters.currentfilter.filterset, where filters, currentfilter and filterset may not be present. so it's heaps easier to do a isDefined( session.currentuser.currentreport.filters.currentfilter.filterset) than structKeyExists(session.currentuser.currentreport , filters) and structKeyExists(session.currentuser.currentreport.filters , currentfilter) and so on. or am i missing something? On 05/06/07, * Haikal Saadh* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Having seen more than my fair share of request scope abuse, I can see why he would. I think easy access to request in CF can cause poor code. But then again, guns don't kill people, people kill people, right? Peter Tilbrook wrote: I agree (disciplined) but he then bagged the request scope so now I am not so sure. -- Cheers Simon Haddon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
One place to NOT use isDefined is on the CGI scope... try this: cfoutput p isDefined(cgi.bob) = #isDefined(cgi.bob)# /p p structKeyExists(cgi, bob) = #structKeyExists(cgi,bob)# /p /cfoutput From what I remeber, the CGI is a magic scope... quote from docs Because some browsers do not support some CGI variables, ColdFusion always returns True when it tests for the existence of a CGI variable, regardless of whether the browser supports the variable. /quote from docs --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
and if you get a bit carried away with struct key names, you can break it too... EG: cfset myStruct = structNew() cfset myStruct[some value here] = bob cfdump var=#myStruct# cfoutput#isDefined(myStruct.some value here)#/cfoutput !--- this line breaks --- cfoutput#structKeyExists(myStruct, some value here)#/cfoutput !--- this line works --- On Jun 5, 9:46 pm, David Harris [EMAIL PROTECTED] wrote: One place to NOT use isDefined is on the CGI scope... try this: cfoutput p isDefined(cgi.bob) = #isDefined(cgi.bob)# /p p structKeyExists(cgi, bob) = #structKeyExists(cgi,bob)# /p /cfoutput From what I remeber, the CGI is a magic scope... quote from docs Because some browsers do not support some CGI variables, ColdFusion always returns True when it tests for the existence of a CGI variable, regardless of whether the browser supports the variable. /quote from docs --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
cfset mystruct[some value here] = nonono :) On 6/5/07, MrBuzzy [EMAIL PROTECTED] wrote: Um where the code 'breaks' in your example. This isn't valid struct usage. Just the same as you can't do this... cfset myStruct.some value here = nonono Or did I miss something? Ie; this would 'break' it too... IsDefined( ! ) Cheers. On 6/5/07, David Harris [EMAIL PROTECTED] wrote: and if you get a bit carried away with struct key names, you can break it too... EG: cfset myStruct = structNew() cfset myStruct[some value here] = bob cfdump var=#myStruct# cfoutput#isDefined( myStruct.some value here)#/cfoutput !--- this line breaks --- cfoutput#structKeyExists(myStruct, some value here)#/cfoutput !--- this line works --- On Jun 5, 9:46 pm, David Harris [EMAIL PROTECTED] wrote: One place to NOT use isDefined is on the CGI scope... try this: cfoutput p isDefined(cgi.bob) = #isDefined(cgi.bob)# /p p structKeyExists(cgi, bob) = #structKeyExists(cgi,bob)# /p /cfoutput From what I remeber, the CGI is a magic scope... quote from docs Because some browsers do not support some CGI variables, ColdFusion always returns True when it tests for the existence of a CGI variable, regardless of whether the browser supports the variable. /quote from docs -- === Raymond Camden, Camden Media Email: [EMAIL PROTECTED] Blog : ray.camdenfamily.com AOL IM : cfjedimaster --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
you can do this (as per my example code): cfset myStruct[some value here] = bob try this one: cfset myStruct = structNew() cfset myStruct[some.value.here and a space too, and an [EMAIL PROTECTED]] = fred cfdump var=#myStruct# it's one of those things that *can* be done, but (as rule of thumb) isn't... but if you do, It'll break isDefined() MrBuzzy wrote: Um where the code 'breaks' in your example. This isn't valid struct usage. Just the same as you can't do this... cfset myStruct.some value here = nonono Or did I miss something? Ie; this would 'break' it too... IsDefined( ! ) Cheers. On 6/5/07, David Harris [EMAIL PROTECTED] wrote: and if you get a bit carried away with struct key names, you can break it too... EG: cfset myStruct = structNew() cfset myStruct[some value here] = bob cfdump var=#myStruct# cfoutput#isDefined( myStruct.some value here)#/cfoutput !--- this line breaks --- cfoutput#structKeyExists(myStruct, some value here)#/cfoutput !--- this line works --- On Jun 5, 9:46 pm, David Harris [EMAIL PROTECTED] wrote: One place to NOT use isDefined is on the CGI scope... try this: cfoutput p isDefined(cgi.bob) = #isDefined(cgi.bob)# /p p structKeyExists(cgi, bob) = #structKeyExists(cgi,bob)# /p /cfoutput From what I remeber, the CGI is a magic scope... quote from docs Because some browsers do not support some CGI variables, ColdFusion always returns True when it tests for the existence of a CGI variable, regardless of whether the browser supports the variable. /quote from docs --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
It is the sort of thing you don't want to teach your developers as I can imagine the heartache that would cause. On 06/06/07, David Harris [EMAIL PROTECTED] wrote: you can do this (as per my example code): cfset myStruct[some value here] = bob try this one: cfset myStruct = structNew() cfset myStruct[some.value.here and a space too, and an [EMAIL PROTECTED]] = fred cfdump var=#myStruct# it's one of those things that *can* be done, but (as rule of thumb) isn't... but if you do, It'll break isDefined() MrBuzzy wrote: Um where the code 'breaks' in your example. This isn't valid struct usage. Just the same as you can't do this... cfset myStruct.some value here = nonono Or did I miss something? Ie; this would 'break' it too... IsDefined( ! ) Cheers. On 6/5/07, David Harris [EMAIL PROTECTED] wrote: and if you get a bit carried away with struct key names, you can break it too... EG: cfset myStruct = structNew() cfset myStruct[some value here] = bob cfdump var=#myStruct# cfoutput#isDefined( myStruct.some value here)#/cfoutput !--- this line breaks --- cfoutput#structKeyExists(myStruct, some value here)#/cfoutput !--- this line works --- On Jun 5, 9:46 pm, David Harris [EMAIL PROTECTED] wrote: One place to NOT use isDefined is on the CGI scope... try this: cfoutput p isDefined(cgi.bob) = #isDefined(cgi.bob)# /p p structKeyExists(cgi, bob) = #structKeyExists(cgi,bob)# /p /cfoutput From what I remeber, the CGI is a magic scope... quote from docs Because some browsers do not support some CGI variables, ColdFusion always returns True when it tests for the existence of a CGI variable, regardless of whether the browser supports the variable. /quote from docs -- Cheers Simon Haddon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
You wouldn't name your own keys this way - on the other hand it's good to know CF can cope with these types of keys if you're writing caching code or something else where you want to associate arbitrary string keys with a value (although I'd probably hash() the string first for good luck). People who've done a CF course with me know that I always try to use structKeyExists() over isDefined() - I use the latter when I need to check that some deeply nested key exists without having to check all the intermediate keys along the way. Robin Robin Hilliard CEO - RocketBoots Pty Limited Consulting . Recruitment . Software Licensing . Training http://www.rocketboots.com.au m+61 418 414 341 e[EMAIL PROTECTED] On 06/06/2007, at 7:14 AM, Simon Haddon wrote: It is the sort of thing you don't want to teach your developers as I can imagine the heartache that would cause. On 06/06/07, David Harris [EMAIL PROTECTED] wrote: you can do this (as per my example code): cfset myStruct[some value here] = bob try this one: cfset myStruct = structNew() cfset myStruct[some.value.here and a space too, and an [EMAIL PROTECTED]] = fred cfdump var=#myStruct# it's one of those things that *can* be done, but (as rule of thumb) isn't... but if you do, It'll break isDefined() --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
structkeyexist is generally regarded as best practice --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
cfif not isdefined(var.foo) ? I use cfif myquery.recordcount Returned at least one record cfelse Naddah! /cfif It is a elegant way to test for the existance of something. User with CFPARAM if you at least require a default of some sort. On 04/06/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- Peter Tilbrook ColdGen Internet Solutions President, ACT and Region ColdFusion Users Group PO Box 2247 Queanbeyan, NSW, 2620 AUSTRALIA http://www.coldgen.com/ http://www.actcfug.com/ Tel: +61-2-6284-2727 Mob: +61-0432-897-437 Email: [EMAIL PROTECTED] MSN Messenger Live: Desktop General --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Grant, It is going to depend on what best suits you, most people for some reason will frown at its use. But there is nothing wrong in using it. On 6/4/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- Senior Coldfusion Developer Aegeon Pty. Ltd. www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Use it all the time, See no reason not to other than where cfparam is more logical. Ie cfparam name=form.checkBoxName default=false / Instead of cfif NOT isDefined(form.checkBoxName) cfset form.checkBoxName = false / /cfif Regards Dale Fraser http://dalefraser.blogspot.com From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of grant Sent: Monday, 4 June 2007 4:42 PM To: cfaussie@googlegroups.com Subject: [cfaussie] isDefined() bad? Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
ParameterExists() is bad. In fact forget I even mentioned it :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
structKeyExists runs quicker - but I hesitate to say isDefined is bad. Personally I'd use what feels best to you. It's not like one will take 0.002 ms and the other will take 2 hours. On 6/4/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- === Raymond Camden, Camden Media Email: [EMAIL PROTECTED] Blog : ray.camdenfamily.com AOL IM : cfjedimaster --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Ray is right. And the fact you are bothering to check at all is good coding practice. Never assume. On 04/06/07, Raymond Camden [EMAIL PROTECTED] wrote: structKeyExists runs quicker - but I hesitate to say isDefined is bad. Personally I'd use what feels best to you. It's not like one will take 0.002 ms and the other will take 2 hours. On 6/4/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- === Raymond Camden, Camden Media Email: [EMAIL PROTECTED] Blog : ray.camdenfamily.com AOL IM : cfjedimaster -- Peter Tilbrook ColdGen Internet Solutions President, ACT and Region ColdFusion Users Group PO Box 2247 Queanbeyan, NSW, 2620 AUSTRALIA http://www.coldgen.com/ http://www.actcfug.com/ Tel: +61-2-6284-2727 Mob: +61-0432-897-437 Email: [EMAIL PROTECTED] MSN Messenger Live: Desktop General --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Hi Grant, The choice is really down to your programming style. I have come from a C / Pascal / PLSQL / Java background and have learned to be very dogmatic and methodical with my programming style. As a team leader I insist that all variables are either declared at the start of a template or to use cfparam if expected and that logical default are set. I find the best part of this approach is that all variables are defined in 1 place and it helps with referencing which variables should exist and what their default values should be. I also find that it reduces the number of variables being used as you have a reference point at the top of the template to check for what is available an why it exists. I am the same in CFCs where I expect that all arguments are defined and either set to required or defaulted with a logical default value. I also expect that all local variables are defined (which is even more important in methods as local variables. Still, having said that. Each to their own Cheers, Simon On 04/06/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- Cheers Simon Haddon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Actually Ray is wrong so to speak... It is a known fact and even though in some cases it makes no difference as the speed differences are very slight, but it is personal preference and nothing more. As far as best practice goes, I would be more concerned on how to optimise the server processing if it is needed. Another thread / post on CF-Talk with some tests, actually shows that depending on the OS one can run slower than the other and vice versa. So if speed an execution is a concern when it matters, use whichever is needed to get that speed increase for your intended platform. Otherwise I would use what is best for your situation. On 6/4/07, Peter Tilbrook [EMAIL PROTECTED] wrote: Ray is right. And the fact you are bothering to check at all is good coding practice. Never assume. On 04/06/07, Raymond Camden [EMAIL PROTECTED] wrote: structKeyExists runs quicker - but I hesitate to say isDefined is bad. Personally I'd use what feels best to you. It's not like one will take 0.002 ms and the other will take 2 hours. On 6/4/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- === Raymond Camden, Camden Media Email: [EMAIL PROTECTED] Blog : ray.camdenfamily.com AOL IM : cfjedimaster -- Peter Tilbrook ColdGen Internet Solutions President, ACT and Region ColdFusion Users Group PO Box 2247 Queanbeyan, NSW, 2620 AUSTRALIA http://www.coldgen.com/ http://www.actcfug.com/ Tel: +61-2-6284-2727 Mob: +61-0432-897-437 Email: [EMAIL PROTECTED] MSN Messenger Live: Desktop General -- Senior Coldfusion Developer Aegeon Pty. Ltd. www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Simon CFC's go without saying, as there will be problems if you do not scope variables with the var scope anyway. just an FYI to any new developers. On 6/4/07, Simon Haddon [EMAIL PROTECTED] wrote: Hi Grant, The choice is really down to your programming style. I have come from a C / Pascal / PLSQL / Java background and have learned to be very dogmatic and methodical with my programming style. As a team leader I insist that all variables are either declared at the start of a template or to use cfparam if expected and that logical default are set. I find the best part of this approach is that all variables are defined in 1 place and it helps with referencing which variables should exist and what their default values should be. I also find that it reduces the number of variables being used as you have a reference point at the top of the template to check for what is available an why it exists. I am the same in CFCs where I expect that all arguments are defined and either set to required or defaulted with a logical default value. I also expect that all local variables are defined (which is even more important in methods as local variables. Still, having said that. Each to their own Cheers, Simon On 04/06/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- Cheers Simon Haddon -- Senior Coldfusion Developer Aegeon Pty. Ltd. www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
I am glad I don't work on one of Andrew Scotts projects. On 04/06/07, Andrew Scott [EMAIL PROTECTED] wrote: Simon CFC's go without saying, as there will be problems if you do not scope variables with the var scope anyway. just an FYI to any new developers. On 6/4/07, Simon Haddon [EMAIL PROTECTED] wrote: Hi Grant, The choice is really down to your programming style. I have come from a C / Pascal / PLSQL / Java background and have learned to be very dogmatic and methodical with my programming style. As a team leader I insist that all variables are either declared at the start of a template or to use cfparam if expected and that logical default are set. I find the best part of this approach is that all variables are defined in 1 place and it helps with referencing which variables should exist and what their default values should be. I also find that it reduces the number of variables being used as you have a reference point at the top of the template to check for what is available an why it exists. I am the same in CFCs where I expect that all arguments are defined and either set to required or defaulted with a logical default value. I also expect that all local variables are defined (which is even more important in methods as local variables. Still, having said that. Each to their own Cheers, Simon On 04/06/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- Cheers Simon Haddon www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 -- Peter Tilbrook ColdGen Internet Solutions President, ACT and Region ColdFusion Users Group PO Box 2247 Queanbeyan, NSW, 2620 AUSTRALIA http://www.coldgen.com/ http://www.actcfug.com/ Tel: +61-2-6284-2727 Mob: +61-0432-897-437 Email: [EMAIL PROTECTED] MSN Messenger Live: Desktop General --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Yeah, well you wouldn't I hate the request scope it is evil. On 6/4/07, Peter Tilbrook [EMAIL PROTECTED] wrote: I am glad I don't work on one of Andrew Scotts projects. On 04/06/07, Andrew Scott [EMAIL PROTECTED] wrote: Simon CFC's go without saying, as there will be problems if you do not scope variables with the var scope anyway. just an FYI to any new developers. On 6/4/07, Simon Haddon [EMAIL PROTECTED] wrote: Hi Grant, The choice is really down to your programming style. I have come from a C / Pascal / PLSQL / Java background and have learned to be very dogmatic and methodical with my programming style. As a team leader I insist that all variables are either declared at the start of a template or to use cfparam if expected and that logical default are set. I find the best part of this approach is that all variables are defined in 1 place and it helps with referencing which variables should exist and what their default values should be. I also find that it reduces the number of variables being used as you have a reference point at the top of the template to check for what is available an why it exists. I am the same in CFCs where I expect that all arguments are defined and either set to required or defaulted with a logical default value. I also expect that all local variables are defined (which is even more important in methods as local variables. Still, having said that. Each to their own Cheers, Simon On 04/06/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- Cheers Simon Haddon www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 -- Peter Tilbrook ColdGen Internet Solutions President, ACT and Region ColdFusion Users Group PO Box 2247 Queanbeyan, NSW, 2620 AUSTRALIA http://www.coldgen.com/ http://www.actcfug.com/ Tel: +61-2-6284-2727 Mob: +61-0432-897-437 Email: [EMAIL PROTECTED] MSN Messenger Live: Desktop General -- Senior Coldfusion Developer Aegeon Pty. Ltd. www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
isDefined() will sometimes return false positives when dealing with SESSION-scoped variables. I do not recall which version of CF this was on, but would have been no earlier than 6.1. Ihave not re- verified this on subsequent versions. At that point in time I switched to using structKeyExists(): I simply don't trust isDefined(). The situation was unpredictable, but replicable (if one was patient during re-testing). It seemed fine with all variable scopes other than session. isDefined() is also limited to using variables using CF's simple variable name format, whereas structKeyExists() is not. -- Adam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
http://corfield.org/blog/index.cfm/do/blog.entry/entry/isDefined_vs_structKeyExists --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
I can't agree with the statement goes without saying as too often I have to say it. I have seen so many bad implementations of CFC that clobber variables left right and centre that it really annoys me and , disappointingly it is allowed in the language. I have taken over projects that I have cringed a the code because of really bad practises and some really dumb thing being done in CFCs so I tend to be of the opinion that it is always better to repeat it . But yes, more so for new programmers so that they get into good habits Cheers, Simon On 04/06/07, Andrew Scott [EMAIL PROTECTED] wrote: Simon CFC's go without saying, as there will be problems if you do not scope variables with the var scope anyway. just an FYI to any new developers. On 6/4/07, Simon Haddon [EMAIL PROTECTED] wrote: Hi Grant, The choice is really down to your programming style. I have come from a C / Pascal / PLSQL / Java background and have learned to be very dogmatic and methodical with my programming style. As a team leader I insist that all variables are either declared at the start of a template or to use cfparam if expected and that logical default are set. I find the best part of this approach is that all variables are defined in 1 place and it helps with referencing which variables should exist and what their default values should be. I also find that it reduces the number of variables being used as you have a reference point at the top of the template to check for what is available an why it exists. I am the same in CFCs where I expect that all arguments are defined and either set to required or defaulted with a logical default value. I also expect that all local variables are defined (which is even more important in methods as local variables. Still, having said that. Each to their own Cheers, Simon On 04/06/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- Cheers Simon Haddon www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 -- Cheers Simon Haddon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Why do you say that Peter? From emails that I have read I think that Andrew is quiet a disciplined programmer? What is the problem? Cheers, Simon On 04/06/07, Peter Tilbrook [EMAIL PROTECTED] wrote: I am glad I don't work on one of Andrew Scotts projects. On 04/06/07, Andrew Scott [EMAIL PROTECTED] wrote: Simon CFC's go without saying, as there will be problems if you do not scope variables with the var scope anyway. just an FYI to any new developers. On 6/4/07, Simon Haddon [EMAIL PROTECTED] wrote: Hi Grant, The choice is really down to your programming style. I have come from a C / Pascal / PLSQL / Java background and have learned to be very dogmatic and methodical with my programming style. As a team leader I insist that all variables are either declared at the start of a template or to use cfparam if expected and that logical default are set. I find the best part of this approach is that all variables are defined in 1 place and it helps with referencing which variables should exist and what their default values should be. I also find that it reduces the number of variables being used as you have a reference point at the top of the template to check for what is available an why it exists. I am the same in CFCs where I expect that all arguments are defined and either set to required or defaulted with a logical default value. I also expect that all local variables are defined (which is even more important in methods as local variables. Still, having said that. Each to their own Cheers, Simon On 04/06/07, grant [EMAIL PROTECTED] wrote: Hi All My patchy memory keeps nagging at me not to use isDefined(). Am I off-base or do I remember something about it being best-practice to avoid isDefined()? Who's got the low-down? Grant -- Cheers Simon Haddon www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 -- Peter Tilbrook ColdGen Internet Solutions President, ACT and Region ColdFusion Users Group PO Box 2247 Queanbeyan, NSW, 2620 AUSTRALIA http://www.coldgen.com/ http://www.actcfug.com/ Tel: +61-2-6284-2727 Mob: +61-0432-897-437 Email: [EMAIL PROTECTED] MSN Messenger Live: Desktop General -- Cheers Simon Haddon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
I agree (disciplined) but he then bagged the request scope so now I am not so sure. -- Peter Tilbrook ColdGen Internet Solutions President, ACT and Region ColdFusion Users Group PO Box 2247 Queanbeyan, NSW, 2620 AUSTRALIA http://www.coldgen.com/ http://www.actcfug.com/ Tel: +61-2-6284-2727 Mob: +61-0432-897-437 Email: [EMAIL PROTECTED] MSN Messenger Live: Desktop General --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Err, how am I wrong? I said there was a speed difference, and you agreed? Or did you think I meant it was ALWAYS faster? If so - I misspoke and you are right to correct me. On 6/4/07, Andrew Scott [EMAIL PROTECTED] wrote: Actually Ray is wrong so to speak... It is a known fact and even though in some cases it makes no difference as the speed differences are very slight, but it is personal preference and nothing more. As far as best practice goes, I would be more concerned on how to optimise the server processing if it is needed. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Ray, I said so to speak, I think the discussion on cftalk about how one is faster on one platform than the other is interesting. On 6/5/07, Raymond Camden [EMAIL PROTECTED] wrote: Err, how am I wrong? I said there was a speed difference, and you agreed? Or did you think I meant it was ALWAYS faster? If so - I misspoke and you are right to correct me. On 6/4/07, Andrew Scott [EMAIL PROTECTED] wrote: Actually Ray is wrong so to speak... It is a known fact and even though in some cases it makes no difference as the speed differences are very slight, but it is personal preference and nothing more. As far as best practice goes, I would be more concerned on how to optimise the server processing if it is needed. -- Senior Coldfusion Developer Aegeon Pty. Ltd. www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
And Peter you need to know when the micky is being taken out of you. Sorry it was just that 2 fridays in a row, the request scope had nothing to do with the problem yet you provided it as an answer:-) On 6/5/07, Peter Tilbrook [EMAIL PROTECTED] wrote: I agree (disciplined) but he then bagged the request scope so now I am not so sure. -- Peter Tilbrook ColdGen Internet Solutions President, ACT and Region ColdFusion Users Group PO Box 2247 Queanbeyan, NSW, 2620 AUSTRALIA http://www.coldgen.com/ http://www.actcfug.com/ Tel: +61-2-6284-2727 Mob: +61-0432-897-437 Email: [EMAIL PROTECTED] MSN Messenger Live: Desktop General -- Senior Coldfusion Developer Aegeon Pty. Ltd. www.aegeon.com.au Phone: +613 8676 4223 Mobile: 0404 998 273 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Having seen more than my fair share of request scope abuse, I can see why he would. I think easy access to request in CF can cause poor code. But then again, guns don't kill people, people kill people, right? Peter Tilbrook wrote: I agree (disciplined) but he then bagged the request scope so now I am not so sure. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Wow thanks for the response people. My question is really out of pure laziness - I have a huge struct that i need to check a key for - the actual key path is session.currentuser.currentreport.filters.currentfilter.filterset, where filters, currentfilter and filterset may not be present. so it's heaps easier to do a isDefined( session.currentuser.currentreport.filters.currentfilter.filterset) than structKeyExists(session.currentuser.currentreport, filters) and structKeyExists(session.currentuser.currentreport.filters, currentfilter) and so on. or am i missing something? On 05/06/07, Haikal Saadh [EMAIL PROTECTED] wrote: Having seen more than my fair share of request scope abuse, I can see why he would. I think easy access to request in CF can cause poor code. But then again, guns don't kill people, people kill people, right? Peter Tilbrook wrote: I agree (disciplined) but he then bagged the request scope so now I am not so sure. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Personally, I favour sane defaults rather than having to check for presence of variables all the time. And the bigger and more complicated your data structs get, I think having to check to see if a variable exists is a quick path to insanity. Side effect of eating too much spaghetti... grant wrote: Wow thanks for the response people. My question is really out of pure laziness - I have a huge struct that i need to check a key for - the actual key path is session.currentuser.currentreport.filters.currentfilter.filterset , where filters, currentfilter and filterset may not be present. so it's heaps easier to do a isDefined(session.currentuser.currentreport.filters.currentfilter.filterset) than structKeyExists(session.currentuser.currentreport , filters) and structKeyExists(session.currentuser.currentreport.filters, currentfilter) and so on. or am i missing something? On 05/06/07, * Haikal Saadh* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Having seen more than my fair share of request scope abuse, I can see why he would. I think easy access to request in CF can cause poor code. But then again, guns don't kill people, people kill people, right? Peter Tilbrook wrote: I agree (disciplined) but he then bagged the request scope so now I am not so sure. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
Then I'll stick to my original statement that there is nothing wrong with isDefined it's better than embedded structKeyExists. Regards Dale Fraser http://dalefraser.blogspot.com http://dalefraser.blogspot.com From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of grant Sent: Tuesday, 5 June 2007 11:02 AM To: cfaussie@googlegroups.com Subject: [cfaussie] Re: isDefined() bad? @Dale: It throws. @Haikal: Good Point. It's that laziness again - setting up and maintaining defaults can be rather tiresome. On 05/06/07, Haikal Saadh [EMAIL PROTECTED] wrote: Personally, I favour sane defaults rather than having to check for presence of variables all the time. And the bigger and more complicated your data structs get, I think having to check to see if a variable exists is a quick path to insanity. Side effect of eating too much spaghetti... grant wrote: Wow thanks for the response people. My question is really out of pure laziness - I have a huge struct that i need to check a key for - the actual key path is session.currentuser.currentreport.filters.currentfilter.filterset , where filters, currentfilter and filterset may not be present. so it's heaps easier to do a isDefined( session.currentuser.currentreport.filters.currentfilter.filterset) than structKeyExists(session.currentuser.currentreport , filters) and structKeyExists(session.currentuser.currentreport.filters , currentfilter) and so on. or am i missing something? On 05/06/07, * Haikal Saadh* [EMAIL PROTECTED] mailto: [EMAIL PROTECTED] wrote: Having seen more than my fair share of request scope abuse, I can see why he would. I think easy access to request in CF can cause poor code. But then again, guns don't kill people, people kill people, right? Peter Tilbrook wrote: I agree (disciplined) but he then bagged the request scope so now I am not so sure. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---
[cfaussie] Re: isDefined() bad?
@Dale: It throws. @Haikal: Good Point. It's that laziness again - setting up and maintaining defaults can be rather tiresome. On 05/06/07, Haikal Saadh [EMAIL PROTECTED] wrote: Personally, I favour sane defaults rather than having to check for presence of variables all the time. And the bigger and more complicated your data structs get, I think having to check to see if a variable exists is a quick path to insanity. Side effect of eating too much spaghetti... grant wrote: Wow thanks for the response people. My question is really out of pure laziness - I have a huge struct that i need to check a key for - the actual key path is session.currentuser.currentreport.filters.currentfilter.filterset , where filters, currentfilter and filterset may not be present. so it's heaps easier to do a isDefined( session.currentuser.currentreport.filters.currentfilter.filterset) than structKeyExists(session.currentuser.currentreport , filters) and structKeyExists(session.currentuser.currentreport.filters, currentfilter) and so on. or am i missing something? On 05/06/07, * Haikal Saadh* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Having seen more than my fair share of request scope abuse, I can see why he would. I think easy access to request in CF can cause poor code. But then again, guns don't kill people, people kill people, right? Peter Tilbrook wrote: I agree (disciplined) but he then bagged the request scope so now I am not so sure. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups cfaussie group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~--~~~~--~~--~--~---