Quote: "
You do realise that functions and procedures were invented precisely because of the problems with having every variable being global, don't you? "
They where invented in PASCAL to teach structured programming, but while the professor (N. Wirth I remember) used it to teach, some people made it a common standard. Later on it was integrated in C (which is a descendant of Pascal)
Depending on your programing style, having all variables global can produce a mess or make your life easier.
I think that having everything usable everywhere makes my life easier, but it implicates that variable names are unique.
To make a program easier to maintain it helps me much more to add comments to remember the algorithms I used used when programing the code.
But do not forget BASICs best thing, you do not have to declare everything which allows for fast and easy prototyping, easy debugging and fast result to show your boss or to your clients. There is a reason that VisualBasic 6 is still around and XNA has its problems to become a standard. (well there are still some COBOL and FORTRAN programers around too)
A typical BASIC function would be sqrt(), which will deliver one result and the variables used to compute the square root will not be needed in the program.
But using a function to alter a objects position and to store the new position in variables is only possible if you declare the variables (as array in DBClassic or as array or globals in DBpro).
If you think declaring variables is a great thing you are better of with COBOL, Pascal, C or ASM. (or using a BASIC that can be set to "option type explicite")
Quote: "Ever tried to rewrite a recursive parameterised function as a subroutine?"
Sure - my first was reading (and printing out) a directory-tree of 'unknown' and 'unlimited' depth, and I never used GOTO in it, but while's and gosub's. BASIC did not have always the FUNCTIONs.
A place to use a goto could a routine reading a file not finding the required input record. Then the processing has to be aborted and this could be done by setting an abort-switch or by going to the the EndAndAbort-routine with goto. Depending on what you want to do. While I prefer the GOSUB with ErrorSwitch-variant as shown here:
ErrorCondition=0
while not file end(infile) and ErrorCondition=0
gosub ReadData
endwhile
If ErrorCondition
print ErrorMessage$
sync
suspend for key
end
endif
rem -----------------
rem some processing
rem -----------------
...
end
rem ----------
ReadData:
rem ----------
read string infile, MyRecord
rem
rem very Simple Validation
rem
if MyRecord.RecordType<>1
ErrorCodition=-1
ErrorMessage$="Invalid recordtype"
endif
return
Note: the variable ErrorMessage$ will be filled in the subroutine ReadData: but used in the main program. Would ReadData() be a function this would not be possible.