both if statements, because the Java switch statement only works on numeric
types (byte, short, int, long and char). Then, factor in the extra
assignment overhead on method 1, count the number of extra lines in method
1, and then the vastly superior readability of method 2, and I think it's a
pretty clear-cut case. At least in my mind. ;)
IMHO, 99.9% of the time, readable, easily maintainable code is way more
valuable than speed. If we're talking about the last fractions of a percent
of performace, than it's almost never worth it. Better to spend 10 minutes
optimizing some query, since that might actually result in several
milliseconds of speed.
Cheers,
barneyb
> -----Original Message-----
> From: Matt Robertson [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, December 16, 2003 1:58 PM
> To: CF-Talk
> Subject: BIG Forms: CFSWITCH or CFIF?
>
> I'm going over old code that has pre-filled form fields based
> on previous user entry. Many are select boxes or radio
> groups with lots of options. The current coding method is
> shown in Method 1 below. The common way I see recommended to
> do this is in Method 2. Before I rewrite this code, I
> thought I'd ask which y'all think is the better approach for
> a big form.
>
> Method 1 is verbose, but its use of cfswitch might be faster?
>
> Method 2 is easier to code, but uses slower cfifs. Lots of
> them on longer forms.
>
> So on a form with a couple of dozen fields like this, which
> do you think is faster/a better approach?
>
> <!---METHOD 1--->
> <cfparam name="variables.LocalAA01" default="" type="string">
> <cfparam name="variables.LocalAA02" default="" type="string">
> <cfswitch _expression_="#QName.AA#">
> <cfcase value="A">
> <cfset variables.LocalAA01=" selected">
> </cfcase>
> <cfcase value="B">
> <cfset variables.LocalAA02=" selected">
> </cfcase>
> <cfdefaultcase>
> <cfset variables.LocalAA01=" selected">
> </cfdefaultcase>
> </cfswitch>
> <SELECT name="AA">
> <OPTION value="A"#variables.LocalAA01#>Choice A
> <OPTION value="B"#variables.LocalAA02#>Choice B
> </SELECT>
>
> <!---METHOD 2--->
> <SELECT name="AA">
> <OPTION value="A"<cfif not CompareNoCase(QName.AA,"A")>
> selected</cfif>>Choice A
> <OPTION value="B"<cfif not CompareNoCase(QName.AA,"B")>
> selected</cfif>>Choice B
> </SELECT>
>
>
> --
> -------------------------------------------
> Matt Robertson, [EMAIL PROTECTED]
> MSB Designs, Inc. http://mysecretbase.com
> -------------------------------------------
>
> --
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

