The RETURN of GOSUB

For other topics related to the FreeBASIC project or its community.
jj2007
Posts: 1161
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: The RETURN of GOSUB

Postby jj2007 » Dec 03, 2017 21:38

Munair wrote:cause of much debate and BASIC's bad reputation, it is just as legitimate as ASM jumps.

Just checked the presence of jmp in two big sources, about 0.5% of all lines. So if that is your percentage in a BASIC source, one GOTO every 200 lines, that's OK ;-)
St_W
Posts: 1467
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: The RETURN of GOSUB

Postby St_W » Dec 03, 2017 22:13

Munair wrote:GOTO on the other hand is powerful and can be handy at times inside (small) code blocks, provided you know what you're doing. While the feature has been the cause of much debate and BASIC's bad reputation, it is just as legitimate as ASM jumps.
The use of GOTO has been criticised because it has been used extensively and wrongly. Of course, if you know what you're doing it's fine, but especially beginners (the target group of BASIC) can't say whether a GOTO's use is a legitimate one and tend to use it instead of loops and branches. Thus the general consent to avoid GOTO whereever possible is a good one - especially for beginners because they won't ran into a situation where a GOTO would really be handy very soon.
MrSwiss
Posts: 3083
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: The RETURN of GOSUB

Postby MrSwiss » Dec 03, 2017 22:15

jj2007 wrote:So if that is your percentage in a BASIC source, one GOTO every 200 lines, that's OK ;-)
As you might have expected, I don't agree with your math.: you'll have to convert
HLL (FB) to ASM first, before counting the jump's (je, jnz, ..., simply all of them).
jj2007
Posts: 1161
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: The RETURN of GOSUB

Postby jj2007 » Dec 03, 2017 23:08

MrSwiss wrote:
jj2007 wrote:So if that is your percentage in a BASIC source, one GOTO every 200 lines, that's OK ;-)
As you might have expected, I don't agree with your math.: you'll have to convert
HLL (FB) to ASM first, before counting the jump's (je, jnz, ..., simply all of them).

A GOTO is an unconditional jump. That is a rare event even in (modern) assembler: 0.5% of a 50,000 lines source, no more.
TeeEmCee
Posts: 248
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: The RETURN of GOSUB

Postby TeeEmCee » Dec 07, 2017 8:49

Trivia: as you can see in the thread fxm linked to from 2006, I created my own reimplementation of GOSUB/RETURN (called GOSUB/RETRACE) using either asm or setjmp/longjmp, which could be used in -lang fb. However it didn't support -gen gcc. We finally got rid of it and the last of the GOSUBs in the OHRRPGCE code this year, after 12 years of code cleanup (there were a lot of GOSUBs to clean up)!
Still have 16 GOTOs. I like FB's ability to exit multiple loops at once with an EXIT; that eliminates one major use of GOTO. And splitting up code into two functions allows using RETURN instead of GOTO in order to jump to cleanup code, eliminating the other major use.

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests