08-09-2024, 09:03 PM
(08-09-2024, 04:03 PM)bplus Wrote: I am curious on other peoples thoughts on drawing the line between using a GoSub and a full blown Sub.
My rule it should be a full blown Sub if there is any chance the Sub might be used in other apps but when in doubt just go Sub.
GoSubs best for applications very specific for the code you ar working. This issues should be decided before Constants and Shared, that is if we are actually thinking ahead a little
My general use for gosub, tends to be ONLY inside subs/functions, and that's to minimize repetitive code that only occurs inside that sub/function.
Code: (Select All)
SUB FOO
SELECT CASE keyhit
CASE left: x = x -1: gosub check_bounds
CASE right: x = x + 1: gosub check_bounds
END SELECT
EXIT FUNCTION
check_bounds:
IF x < 0 then x = _WIDTH -1
IF x >= _WIDTH then x = 0
RETURN
END SUB
Something similar to the above, where that same code might be called multiple times inside the same SUB, and which will never possibly be of any use anywhere else inside the main program as a standalone SUB might be.