Pharoah
Pharoah

May 21st, 2009, 7:18 pm #11

*In English or Spanish please :)
Quote
Share

Joined: February 2nd, 2006, 10:38 pm

May 21st, 2009, 8:02 pm #12

*I think he was kidding. Using GOSUB without RETURN also eats some stack space each time.
* Ya think? LOL
Quote
Like
Share

Kirk
Kirk

May 21st, 2009, 8:06 pm #13

The GOSUB Hammer can seriously damage the opposite hand's thumb.

The Nailgun SUB can drive nails 10 times as fast and can also be used as a weapon if Canadian Klingons are around. You can only throw a hammer once!
Don't force me to emotionally compromise you again Spock!
Quote
Share

Joined: February 2nd, 2006, 10:38 pm

May 21st, 2009, 8:15 pm #14

* I have no emotions Captain. Throw that hammer if you dare!
Quote
Like
Share

Galleon
Galleon

May 21st, 2009, 8:20 pm #15

I'm writing a piece of code that I hope will be useful to others, and I want to keep it small and simple by having everything in one function rather than using multiple functions and either passing the same arrays around or using globals. Normally I'm not a big fan of GOSUBs but they seem to be good for this particular application because I don't really need the abstraction of full blown SUBs or FUNCTIONs. What are your thoughts on the use of GOSUBs in a post-GWBASIC world?
Particularly when passing an array's index value or a string. However, I believe it is the scale of the program that matters most here. How big is too big to use GOSUB? How many GOSUBs are too much?
The are no set-in-concrete answers to this. Take the following program MOONCR.BAS for example:
http://www.petesqbsite.com/downloads/mooncr.zip
Even though the use of GOSUB is well organised it makes the program difficult to navigate and to understand exactly which variables are being 'passed'.
Quote
Share

London
London

May 21st, 2009, 10:19 pm #16

The GOSUB Hammer can seriously damage the opposite hand's thumb.

The Nailgun SUB can drive nails 10 times as fast and can also be used as a weapon if Canadian Klingons are around. You can only throw a hammer once!
*
Quote
Share

Joined: March 24th, 2004, 5:02 am

May 21st, 2009, 11:10 pm #17

I'm writing a piece of code that I hope will be useful to others, and I want to keep it small and simple by having everything in one function rather than using multiple functions and either passing the same arrays around or using globals. Normally I'm not a big fan of GOSUBs but they seem to be good for this particular application because I don't really need the abstraction of full blown SUBs or FUNCTIONs. What are your thoughts on the use of GOSUBs in a post-GWBASIC world?
I can only think of one real reason not to use GOSUBs if they appear to be the best tool for the job, and that reason is that they have the potential to encourage beginners to overuse them if they read your code. However if you're already using SUBs or FUNCTIONs then I think that danger is largely mitigated.

So, use the best tool for the job - failing that, use a GOOD tool for the job. Remember, "GOTO is evil. This does not mean it should be avoided, only that it should be used when it is the lesser of the evils."

GOSUBs are held in better regard than you think: they don't exist in standard C, but GNU C does allow them. Or rather, their slightly neater C equivalent, nested functions. See: http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

I know the developers of GRUB (a bootloader for Linux and several other UNIX-like systems) are fond of these things.
Quote
Like
Share

Ben
Ben

May 21st, 2009, 11:31 pm #18

*
* How?
Quote
Share

Joined: February 2nd, 2006, 10:38 pm

May 22nd, 2009, 12:02 am #19

* Please go to the "Nailgun Forum" for details........
Quote
Like
Share

Joined: May 31st, 2004, 10:14 am

May 22nd, 2009, 7:34 pm #20

I'm writing a piece of code that I hope will be useful to others, and I want to keep it small and simple by having everything in one function rather than using multiple functions and either passing the same arrays around or using globals. Normally I'm not a big fan of GOSUBs but they seem to be good for this particular application because I don't really need the abstraction of full blown SUBs or FUNCTIONs. What are your thoughts on the use of GOSUBs in a post-GWBASIC world?
'This can be useful in some applications. Multiple
'entry points (as some know) are also used in ASM:

CLS
PRINT
GOSUB a
PRINT
GOSUB b
PRINT
GOSUB c
END

a:
PRINT "Been to a"
b:
PRINT "Been to b"
c:
PRINT "Been to c"
RETURN

'-Bob
Last edited by qb432l on May 22nd, 2009, 7:35 pm, edited 1 time in total.
Quote
Like
Share