QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: hanness on April 16, 2020, 11:21:20 am

Title: Need a little help with terminology
Post by: hanness on April 16, 2020, 11:21:20 am
I always refer to the following structure as a subroutine:

MySubroutine:
' some code is located here
Return

But how do I differentiate that from this...

Sub Whatever
' some code is located here
End Sub
Title: Re: Need a little help with terminology
Post by: Pete on April 16, 2020, 11:39:58 am
Well the only difference I'm aware of is that GOSUB calls a local subroutine, where a sub call calls a subroutine, which is not in the local main or current local sub. I do't know, maybe call it MyGoSub Routine? Other than terminology, why is this important to you?

Pete
Title: Re: Need a little help with terminology
Post by: hanness on April 16, 2020, 11:51:30 am
Ah yes, local subroutine would be a good term.

It's just that I have a program that is up to about 8,000 lines of code now and I'm going through it with a fine tooth comb and adding very detailed comments as one of my tasks. Just want to be very precise to avoid any potential confusion when I reference a local subroutine vs those routines that appear after the end of the main program (the sub... end sub routines).

Thanks for the help once again.

Title: Re: Need a little help with terminology
Post by: Pete on April 16, 2020, 01:14:14 pm
Hey, we're in a similar boat. I've been working on a project for 2 months now. Currently, its a little over 10,000 lines of code, and right, programs of this magnitude are always a challenge to pick through the old code when you want to make modifications or additions. I try to watch what I name things, so I can pick needles out of the hay stack faster. I also like to use lots of GOSUB routines, and in this way...

SUB Pete

GOSUB load_data

GOSUB sort_data

GOSUB find_duplicates

GOSUB remove_duplicates

END SUB

In other words, it paints the big picture, with the need for me scrolling on endlessly through the subs, to see what comes next. Now if I need to look closely at the code, the good news is I line up all those local subroutines in the order they are called. So when I start with the first routine and read, the only difference is somewhere I encounter the RETURN statement and the next local sub-routine label.

I used to only use GOSUB statements when that particular routine was called two or more times in the local sub or main. Now, I use it more as a map. I blame that on...ah, on... oh, on old age.

Pete

Note: Steve would never post an example with his name as a sub-routine. He considers himself the main.
Title: Re: Need a little help with terminology
Post by: Richard Frost on April 17, 2020, 12:46:14 am
A rather big difference is the scope of variables.
With SUB, a variable is only accessible if it's passed,
or declared with DIM SHARED.