ioscat wrote:i'm not sure but IF statement is highcost function to calculate, so if you can find some aroud way - you ought to use it. Am I right?
Possibly, and possibly not.
For some reason I'm calling to mind an article that I read recently, and now have
the words of Jeff Atwood (of StackExchange fame/infamy) pounding in my head:
Jeff Atwood wrote:All that's left is micro-optimization, and the minute you begin worrying about tiny little optimizations, you've already gone down the wrong path.
As he in turn quoted from Bill Murray in the movie
Meatballs:
Bill Murray wrote:It just doesn't matter! It just doesn't matter!
I don't know whether anyone has ever run a test on how long an If() takes to execute (and you can bet that this will be different in a TI than in Rules, since they're entirely different creatures) but my bet is that for a single If(), or even a couple of nested if()s, it won't be much. If the difference between a single If() and an alternative method is in milliseconds, then you'll probably have spent more time worrying about the optimisation than you'll ever gain by making it. But when you're getting beyond (or even
to) 30 If()s per cell, it's not the if() function itself that's the problem. There are in fact two problems.
The first is the multitude of them that need to be evaluated for any given value. If I may paraphrase Col. Bernd Von Kielst:
The server processor in processing If() functions is like an elephant attacking a host of ants. The elephant will kill thousands, perhaps even millions, of ants, but in the end their numbers will overcome him, and his performance will be eaten to the bone.
That having been said it may also to some extent depend on how If() is coded internally, which I don't have an answer to. If it evaluates from outside in and stops when it hits the first True condition,
and if the majority of the evaluations will be amongst the first few of the statements then again... it probably doesn't matter.
If, on the other hand, it acts like .Net's IIF() function and always evaluates both True and False conditions regardless then we're back to ants and elephants.
But the second problem is
another issue that Atwood raised:
Jeff Atwood wrote:Stop micro-optimizing and start macro-optimizing: per Lippert, code that makes sense is code which can be analyzed and maintained, and that makes it performant.
One of the reasons that I like using .xrus for rules is that they let me break out the True and False blocks of an If() function and use colour coded rows to indicate where the True and False parts of the code occur. However even using that technique I find it difficult to believe that n blocks of code each containing 30 If() functions will be particularly easy to analyse and maintain. A new admin trying to figure out how the code flows from that (or who tries to make a change to the code and then has to use 30 different highlighters and a magnifying glass to work out where s/he missed a bracket) is likely to suspect that Dante might have neglected to describe one of the circles of Hell. If the code is difficult and time consuming to understand, update and maintain... then it's probably time to look for different code.