I agree with Sean.  IIF is slow and can ALWAYS be avoided.

I'm very fond of using the following syntax as Sean pointed out, except that
I use style sheet classes instead of arrays:

<cfset theMod = currentRow MOD 2>
<td class="alternateRowColor#theMod#">
..
</td>

IIF screws up the color coding of the editor and looks messy and is also
difficult to immediately comprehend when scanning a page.  It really has no
place in well written code.

+-----------------------------------------------+
Bryan Love
  Macromedia Certified Professional
  Internet Application Developer
  Database Analyst
TeleCommunication Systems
[EMAIL PROTECTED]
+-----------------------------------------------+

"...'If there must be trouble, let it be in my day, that my child may have
peace'..."
        - Thomas Paine, The American Crisis



-----Original Message-----
From: Sean A Corfield [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 09, 2002 11:00 AM
To: CF-Talk
Subject: Re: iif usage


On Sunday, September 8, 2002, at 09:33 , Joe Eugene wrote:
> I dont agree with Sean or Dave...

That doesn't surprise me Joe :)

> i dont think IIF is necessary but its
> a very useful function ... "IF USED PROPERLY"

I didn't say it wasn't *useful* - I just said it was bad practice and 
could always be avoided.

> Many of you guys dont agree.. but i personally prefer using IIF and i
> use it only when necessary... a good example would be...table row colors.
> ..

It is NEVER necessary. You even admit that above!

> i dont use the above for complex logic...write cfscript blocks of code...
> i am not very fond of <cfif> contructs...

But you can structure your code to be concise without iif(). Since you 
want alternating colors, you should see that rownum mod 2 will give 
alternating 1, 0, 1, 0 values. So you could construct a two-element array 
containing the colors you want - do this above the loop over the table 
rows - and then each row just accesses the appropriate element of the 
array.

The main benefit of this approach is that it keeps the color specification 
separate from the row logic instead of being embedded in the table and it 
also scales easily to alternately through more colors or alternating on 
blocks of rows.

And of course it doesn't use iif() which is a big plus in my book.

If you want to use iif() instead of <cfif>, that's up to you. Just don't 
ask me for a job (or a reference)... :)

Sean A Corfield -- http://www.corfield.org/blog/

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


______________________________________________________________________
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to