Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SUBS or GOSUB; for library projects, which do you guys prefer?
#1
I just wrapped up a new faster edition of my string math routines. Jack provided another source of string math code from Treebeard. Treebeard's structure have many, may subs and functions. If you added it to your routines, you would add 50 subs/functions to work with addition, subtraction, multiplication, division, and square root calculations. Now you only need to call one sub for each of those, and then those 5 subs call the other subs and functions. In my original string math, which did not include square root, everything was contained in one sub. YOU called one sub, using an operator like "+", "-", etc. and the string math operation was returned. That's a lot less clutter when adding such a routine to function in another program.

So...

Which method do you guys prefer, and what pros and cons do you see in both if SEVERAL are needed to complete a library?

For me, it's the following.

SUBS and FUNCTIONS:

Pros:
Easier for the developer to work with when debugging.
Fewer problems or no need at all to clear variables.
Advantage to passing variables by reference. It's a neat trick to change the names without additional renaming statements.
Faster to code, provided you use TYPES for many passed variables to cut down on the variable lists passed.
Can be identified in the editor (IDE) easily enough if a prefix is used for each like SUB Smath_Mult, SUB SMath_DIV, etc.

Cons:
Harder for the user to find their own program subs and functions n the mix.
Cluttered SUB/FUNCTIONS lists to sort through in the IDE.
Requires multiple CALL arguments instead of just a single call the library sub like CALL StringMath().


------------------------------------------------------------------------------------------------------------------------

GOSUBs in a single SUB

Pros:
All code contained in one easy to port sub routine.
Less project time working out passing variables; (e.g., GOSUB StringMult instead of String_Mult var1, va2, var3, etc.
Keeps the subs and function list in the editor clean, making it easier to navigate the program to which it is ported.

Cons:
More work making sure variable names do not conflict with other GOSUB routines, meaningĀ  more need for unique variable names.
More work zeroing variables.
Possible stack space issues if too nested and a RETURN is missed.
Harder for the developer to work on in the IDE, although Alt arrow left indexing helps some.

--------------------------------------------------------------------------------------------------------------------------

Anyway, what other pros and cons come to mind and again, which method would you rather use as a library addition in your own programming projects?

Pete
Reply


Messages In This Thread
SUBS or GOSUB; for library projects, which do you guys prefer? - by Pete - 08-27-2022, 05:31 PM



Users browsing this thread: 1 Guest(s)