Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SUBS or GOSUB; for library projects, which do you guys prefer?
#4
(08-27-2022, 07:13 PM)bplus Wrote: The only way you could possibly use a GoSub in a library is to have it inside a Sub or Function.

You can put a GOSUB library anywhere inside your main code.

Code: (Select All)
GOTO skipLibrary2022.08.27
 
proveExample:
PRINT "Here's an example of a GOSUB library!"
RETURN

skipLibrary2022.08.27:

Feel free to save that as a *.BM library file and $INCLUDE it in any of your programs, anywhere in the main module.   Just call it with GOSUB proveExample.



That said, I'd *never* go such a route.  For starters, the routine is *only* callable from the main module -- it won't work with any of your other SUB or FUNCTION modules.  Any variables in it are all in scope, so if you use a FOR i ...NEXT, you better make certain you're not corrupting the value of i elsewhere with it.  There's no easy way to free variables used in the gosub, and all-in-all, it's just one of those tools of the caveman programmer like LET, in my opinion.  I can't think of more than a handful of times in my long years of programming where I thought "GOSUB might be better than SUB for this".  When I did, it was almost exclusively just for use *inside a SUB* itself.  Wink
Reply


Messages In This Thread
RE: SUBS or GOSUB; for library projects, which do you guys prefer? - by SMcNeill - 08-27-2022, 07:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Aloha from Maui guys. Cobalt 18 3,027 01-20-2025, 07:33 PM
Last Post: Pete
  What do you guys like to use for mouse mapping? Pete 32 4,468 01-07-2025, 03:35 PM
Last Post: OldMoses
  Hey guys, riddle me this... Pete 8 1,358 01-01-2025, 02:23 AM
Last Post: Pete
  Viewing SUBs in IDE TerryRitchie 0 473 05-27-2024, 06:24 PM
Last Post: TerryRitchie
  Coverting GOSUB to GOTO? James D Jarvis 15 2,550 12-31-2022, 07:19 PM
Last Post: SMcNeill

Forum Jump:


Users browsing this thread: 1 Guest(s)