Author Topic: Need a little help with terminology  (Read 2769 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Need a little help with terminology
« 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

Marked as best answer by hanness on April 16, 2020, 07:51:33 am

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Need a little help with terminology
« Reply #1 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Need a little help with terminology
« Reply #2 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.


Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Need a little help with terminology
« Reply #3 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.
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Need a little help with terminology
« Reply #4 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.
It works better if you plug it in.