(the UDF, that is...)

This post illustrates where Sanity can be helpful. I have recently enhanced the UDF to alert for unterminated command pairs (If/EndIf, Do/Until, While/Loop, and Select/EndSelect) and had been scouring the board for examples of "insane" code. The raw code in the above post has over 250 levels of unterminated IF statements.

The question I have is - what is a REASONABLE level of open If, While, Do, and Select statements? I currently permit 40 levels in the UDF, after which the UDF breaks down and cries (at the condition of your code, and the insanity of it all, not that it can't keep up). Actually, Sanity simply aborts with a "Too many open levels- check your code!" error.

So - is 40 open If statements a reasonable limit? I apply the same limit to the other command-pairs, even though I belive that 40 is too excessive (by about 38!) for nested loops and selects. Personally, I've never used more than 4-5 nested levels of If or loops, even in the complex code projects, but I want to provide something that is useful to all.

The new Sanity will generate an additional report, something like this:
 Code:
Searching for available UDFs.......................
 187 UDFs located in 112 files.
No UDFs needed for this generation!
Generation of test2.kix is complete!

000001: Main
000005:  If $X = 1
000007:  EndIf
000009:  If $X = 1
000010:   While $X < 2
000011:    If $X = 1
000013:    Loop
 - WARNING: Unterminated If when closing While!
000014:   EndIf
000015:  EndIf
000020: Function: X1
000022:  If $X = 1
000024:  EndIf
000026:  While/Loop
000029:  While $X < 10
000031:  Loop
000033:  While $X < 10
000038: EndFunction X1
 - WARNING: Unterminated While when closing function!

000041: Function: X2
 - WARNING: Open If, While, Do or Select when defining function.
000043:  If/EndIf
000046:  Select
000051:  EndSelect
 - WARNING: Unterminated While when closing Select!
000053:  Select
000067: EndFunction X2
 - WARNING: Unterminated Select when closing function!

000069: Function: x3
 - WARNING: Open If, While, Do or Select when defining function.
000071:  If $X = 1
WARNING: Missing EndFunction!
WARNING: 1 Unterminated If statement(s)!
WARNING: 1 Unterminated While statement(s)!
WARNING: 1 Unterminated Select statement(s)!
 8 warnings generated, 73 lines processed.
This output was from KGen. You can see that it indents the code fragments by 1 space per level, making it easy to catch the mismatched items. The actual line containing the If or While is displayed in the report. Between that and the line number it should be easy to locate in your source file.

Comments? Suggestions?

Glenn
_________________________
Actually I am a Rocket Scientist! \:D