If .. Goto not documented?

Forum for discussion about the documentation project.
Post Reply
FreeFox
Posts: 69
Joined: Sep 28, 2016 23:45

If .. Goto not documented?

Post by FreeFox »

I noticed today that an old BASIC construct, If .. Goto, still works in FB (even in the 'default' dialect) but doesn't appear to be documented anywhere - at least not in the obvious places.

So, for example, the following compiles and works fine:

Code: Select all

dim xx as integer = 3
if xx = 3 goto finito   '' no then!
realEnd:
end

finito:
print "Finito!"
goto realEnd


Could some-one check this out please and, if I'm wrong, post a link to the appropriate page.

Thanks in advance.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: If .. Goto not documented?

Post by fxm »

If .. Goto works also in QB, and is also not documented!
(If .. Gosub does not work)

I suppose that for compatibility with very old Basic languages, the single-line syntax:
If expression Then Goto label [Else [statement(s)]] [End If]
can be shortened into:
If expression Goto label [Else [statement(s)]] [End If]
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: If .. Goto not documented?

Post by fxm »

KeyPgIfthen → fxm ['If...Then Goto' can be shortened into 'If...Goto']
FreeFox
Posts: 69
Joined: Sep 28, 2016 23:45

Re: If .. Goto not documented?

Post by FreeFox »

Excellent, thanks for dealing with this so quickly :)

I checked the manuals for VB-DOS and PDS and couldn't find it mentioned in those either. So it looks like FB is now the first BASIC to document this feature for more than 30 years!
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: If .. Goto not documented?

Post by caseih »

It's good to know the tradition of enabling so-called "spaghetti code" is alive and well in modern incarnations of BASIC! ;) Not that IF..GOTO has to be messy, but if often was in old code with line numbers. ON ... GOTO or ON ... GOSUB were quite common back in the day as well. Jump tables have their place if they are documented, which they often weren't. Fun times.
FreeFox
Posts: 69
Joined: Sep 28, 2016 23:45

Re: If .. Goto not documented?

Post by FreeFox »

Although I'm a bit of a traditionalist, I certainly wouldn't want to see the return of line numbers which are best confined to the dustbin of programming history!

But I must admit it gives me a 'warm feeling' to see that crufty old stuff such as If .. Goto and On .. Goto are still supported even if I can't see myself using them much :)

The humble Goto has had a very bad press since the pronouncements of the late great Edsger Dijkstra and whilst he had a point about the spaghetti code of the time, it still has its place in modern programming.

If you look at the code generated by compilers which compile to C (such as FB 64 bit) it's full of labels and gotos.

I've also seen programmers using other languages go to ridiculous lengths to avoid using Goto in complex code by creating Boolean tests everywhere which just made the code even harder to read and probably slower, to boot!
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: If .. Goto not documented?

Post by counting_pine »

One problem about documenting stuff like this is that it binds it into the definition of the FreeBASIC language, and it means that any attempts to refine or reimplement the language will mean having to continue this quirk or risk breaking code and upsetting people.
I've come to think that it isn't necessarily worth documenting every quirk and edge case of the language, because of the extra burden it places on the specification.
FreeFox
Posts: 69
Joined: Sep 28, 2016 23:45

Re: If .. Goto not documented?

Post by FreeFox »

I can see where you're coming from and I'd agree with you up to a point.

Also, even if it were desirable, it's just not feasible to document everything and even languages with formal specifications have their 'dark corners'.

But this particular feature is basic syntax and it's difficult to see what changes could be made to the FB language which would necessitate its removal.

I've traced it back to GW-Basic (http://www.gw-basic.com/gw-man.pdf) and I see that QB64 have it documented as well (http://www.qb64.net/wiki/index.php?title=IF...THEN). So I can't really see what harm it does to document it in FB, given the succinct way @fxm has done it.
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: If .. Goto not documented?

Post by St_W »

FreeFox wrote:So I can't really see what harm it does to document it in FB, given the succinct way @fxm has done it.
The thing is that undocumented means in general "don't use" while as soon as something is documented (and not additionally marked as deprecated, obsolete, ...) it means that it can be used.
Additionally, if it's not documented it is easy to change (for the compiler devs; like e.g. removing that legacy syntax) because they don't have to care about compatibility (the programmer has to solve problems if he/she's using undocumented stuff). As soon as it's documented the compiler devs are responsible for maintaining backward compatibility and/or providing a migration path.

And in this particular case I'd opt for "don't use", so I'd mark it as obsolete/outdated/deprecated/... at least. Maybe "-lang qb" could be an exception where such legacy constructs could be still allowed.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: If .. Goto not documented?

Post by fxm »

KeyPgIfthen → fxm [If...Goto, as shortcut for If...Then Goto, exists but is deprecated]
FreeFox
Posts: 69
Joined: Sep 28, 2016 23:45

Re: If .. Goto not documented?

Post by FreeFox »

Fair enough, I'm happy with that :)

Incidentally and on a similar theme, just noticed an inconsistency on the FreeBASIC dialects page (http://www.freebasic.net/wiki/wikka.php ... erDialects).

As you'll see, it says there in point 8 that both On ... Gosub and On ... Goto are not supported in -lang fb. However, the page for On...Goto (http://www.freebasic.net/wiki/wikka.php ... eyPgOngoto) does not confirm this and in fact it works fine.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: If .. Goto not documented?

Post by fxm »

CompilerDialects → fxm [in -lang fb, On...Gosub is not supported, but On...Goto is allowed]
FreeFox
Posts: 69
Joined: Sep 28, 2016 23:45

Re: If .. Goto not documented?

Post by FreeFox »

Great, thanks ;)
Post Reply