Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Nested IIF()'s Versus ICASE()
Message
From
03/03/2008 20:19:01
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01298206
Message ID:
01298308
Views:
24
>>I am pretty sure that Icase is faster, but whether the difference is significant or not, I don't know. But the improved readability can be translated into improved maintainability, and that's enough for me. I have been able to tidy up some rally messy code.
>
>I agree. I'm in the camp that like to maintain clean code.

Here's an example of ICase() translated into nested iif()s, while trying to keep the readability
#IF hV9
	lnA=ICASE(lnB=0,0,	;
		lnB=1,1,	;
		INLIST(lnB,2,3,5),3,	;
		INLIST(lnB,6,7),4,	;
		lnB=4,7,	;
		0)
#ELSE
	lnA=IIF(lnB=0,0,	;
		IIF(lnB=1,1,	;
		IIF(INLIST(lnB,2,3,5),3,	;
		IIF(INLIST(lnB,6,7),4,	;
		IIF(lnB=4,7,	;
		0)))))
#ENDIF
The conversion from the above to the below turned out to be just inserting iif( in front of every expression, then closing parentheses in the end. This way they look just equally readable to me... though Icase() is nicer.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform