Will Recursive function take lots of time?

Hi, I have used a recursive function to find result of a logical expression.

My doubt is using recursion will make application slow???

Function ValidateExpression(condition As Variant, Source As NotesUIDocument) As Boolean

        Dim BResult As Boolean

        BResult=True

        temp=condition

        If Instr(condition,"&") Then

                    condition1=""

                    condition2=""

                    condition1=Strrightback(condition,"&")

                    condition2=Strleftback(condition,"&")

                    BResult=ValidateExpression(condition1,Source) And ValidateExpression(condition2,Source)

                    ValidateExpression=BResult     

                    Exit Function

        End If 

        If Instr(condition,"|") Then

                    condition1=""

                    condition2=""

                    condition1=Strrightback(condition,"|")

                    condition2=Strleftback(condition,"|")

                    BResult=ValidateExpression(condition1,Source) Or ValidateExpression(condition2,Source)

                    ValidateExpression=BResult

                    Exit Function

        End If 

             If Instr(temp,"!=")    Then

                   field_value= Strright(condition,"!=")

                    field_name=Strleft(condition,"!=")

                    If Instr(source.FieldGetText(field_name),field_value)=0 Then

                                ValidateExpression=True

                    Else

                              ValidateExpression=False

                    End If

        Elseif Instr(temp,"=") Then

                    field_value= Strright(condition,"=")

                    field_name=Strleft(condition,"=")

                    If Instr(source.FieldGetText(field_name),field_value)  Then

                                ValidateExpression=True

                    Else

                                ValidateExpression=False

                    End If

        End If

End Function

Any idea…?

Cheers

Merrin

Subject: RE: Will Recursive function take lots of time?

It seems to me you are trying to duplicate a subset of the Evaluate function. Why don’t you just use Evaluate?

To answer the question you asked, I see no reason this function might be slower for the same expression on the same form in a test environment versus development. Nor do I think it would be slow enough for you to notice a pause for any expression of reasonable length. What makes you think this is the source of the delay?

I would expect the form might be slower because it contains lookups to views that contain a lot more documents in the test database than they do in your development database, so it will take more time to recalculate. But the only thing this function is doing that involves the form is reading the text out of fields. For that, the number of documents in the database shouldn’t matter.

Subject: *The only real answer is “It depends”, but likely it will. Does it seem to?

Subject: RE: *The only real answer is “It depends”, but likely it will. Does it seem to?

In development environment it is fast,But when i moved it to test environment ,it is becoming slow…

Subject: RE: *The only real answer is “It depends”, but likely it will. Does it seem to?

There should be no difference between environments, since the code executes on the workstation against an open UI document in both cases. The difference likely has to do with the documents and the condition strings used in testing.

I can see a couple of potential problems, though – this will not return the desired result for complex condition strings because it doesn’t follow the standard order of operations and does not allow parenthetical grouping. How would the user check for (A and B) OR (C and not D)?

Subject: RE: *The only real answer is “It depends”, but likely it will. Does it seem to?

In this case,conditions are very simple ,it will be combination of & and | .It is not having parenthetical groupings also.

Actually location of development server and Test server is different.Test server is not located in my location.So speed can depend on network load.

I just want to confirm it.

Subject: Will Recursive function take lots of time?

Recursion always introduces a performance hit because function calls introduce additional overhead. Making a function call means that the current instruction pointer, the pointer to the function being called, plus all of the parameters must be pushed onto the stack and an interrupt must be generated. In many cases, tasks that can be solved with recursion can also be solved without it and the non-recursive implementations (provided that they are well-written of course) are generally more performant than the recursive ones. I know that I am painting with pretty broad brush strokes here so flame on I guess.

Subject: I think it was quite well stated.

There are times it is good to use recursion, but there are plenty of bad ones as well. The trade off is usually cleaner code and much more debugging and a performance hit (if you choose recursion) or somewhat more convoluted code with less debugging and better performance (if you choose an iterative approach). I use both as the occasion warrants, but am very, very careful when I use recursion, as you can dig a pretty deap hole for yourself recursively.