#101090 - 2003-05-18 10:48 PM
Write understandable posts
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
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
|
|
Top
|
|
|
|
#101094 - 2003-05-18 11:24 PM
Re: Write understandable posts
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Lonk,
Make your UDF's non-cryptic, in this way you make it easyer to resuse them. As i said in my starting post: "Scripts/UDF's" should only be used as inspirations
Les,
The scripts i posted was to prove that once the script is read/tokenized the execution time for $DirectoryName is the same as for $S
-Erik
|
|
Top
|
|
|
|
#101099 - 2003-05-19 11:03 AM
Re: Write understandable posts
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
quote: "this script is made cryptic so you would not have the temptation to break it and blame my a*s"
how it could be clearer?
You could explain what an "a*s" is and why I should want to blame it for anything.
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1782 anonymous users online.
|
|
|