Tokenizing scripts.

After Ruud had implemented tokenizing of scripts from KiX 4.2, there is no excuse for NOT using descriptive variable names and omitting comments.

In previous vesions the length of variable names could impact the execution time of scripts (specially recursive scripts)

So please, in the future, don't use variable names like: $, $_, $!, $1, $2 etc... when you post a script.

Anyway we/i dont use the Scripts/UDF's in the form they are posted on the board, but use them as inspirations, so please don't hide the gold!

I will supply two scripts that executes in same time, but is in readable/Not readable form.

Readable script:
code:
Function ListFiles($DirectoryName)
; List all filenames in $DirectoryName and all subdirectories beneth it

$FileName = Dir($DirectoryName + "\*.*")
While @Error = 0 And $FileName
If $FileName <> "." And $FileName <> ".."
If GetFileATTR($DirectoryName + "\" + $FileName) & 16 ; This is a directory, list files using recursion
; Recursion:
; In this situation we want to list all files in a directory, and all files in all subdirectories under this subdirectory
; So the function ListFiles(), The function we are inside calls itself when it meets subdirectories
ListFiles($DirectoryName + "\" + $FileName) ; Recursion (call MySelf with new parameter) ;)
Else
? $DirectoryName + "\" + $FileName
EndIf
EndIf
$FileName = Dir()
Loop

EndFunction

Hard to read script
code:
Function L($S)
$=Dir($S + "\*.*")
While @Error=0 And $
If $<>"." And $<>".."
If GetFileATTR($S+"\"+$) & 16
L($S+"\"+$)
Else
?$S+"\"+$
EndIf
EndIf
$=Dir()
Loop
EndFunction

The code i used for testing:
code:
Break On

; Dummy-run to fill buffer
L(%WinDir%)

$Start = @Ticks
ListFiles(%WinDir%)
$ElapsedLong = @Ticks + $Start

$Start = @Ticks
L(%WinDir%)
$ElapsedShort = @Ticks + $Start

? 'Elapsed time long script : ' + $ElapsedLong
? 'Elapsed time Short script: ' + $ElapsedShort

Get $x
Return

-Erik