To me SUBs & FUNCTIONs are just routines and if I want isolation, a one line LOCAL statement declaring variables used for that purpose is painless.
Hmmm, my perspective on SUBs and FUNCTIONs is different.
A flat, linear model where Subs and Functions are merely routines, similar to GOSUB/RETURN, would not allow recursion. As every time a SUB was re-entered the pre-existing (local) var values could be corrupted.
Regardless of
name spaces, it's been my experience that data contained within Subs and Funcs should be isolated from the rest of the program. Of course, Subs and Funcs can see and access global variables in existance in the
main body, (lowest level of the program). Additionally, Subs can access any variables passed to that Sub/Func.
The
scope of a variable, when declared and assigned to in a Sub/Func, should be exclusive to that Sub/Func. Otherwise, data could become corrupted.
globalVar = 1
CALL MySub()
PRINT "\nMAIN:output\n"
PRINT "globalVar=", globalVar, "\n"
PRINT "localVar=", localVar, "\n"
END
SUB MySub
localVar = 2
PRINT "SUB:output\n"
PRINT "globalVar=", globalVar, "\n"
PRINT "localVar=", localVar, "\n"
END SUB
Unfortunately, (using SB) the above illustration displays the same output in both cases.
localvar, created in
SUB mysub, is not destroyed upon exiting the SUB.
It remains alive after the Sub has been exited and is visible to the Main Body of the program.
Further tests show that I can
force localVar to be exclusively local with:
Local localVar
localVar = 2