boxgaming / qbjs

QBasic for the web
https://qbjs.org
MIT License
51 stars 9 forks source link

GOTO not supported? #38

Closed fredlcore closed 1 year ago

fredlcore commented 1 year ago

First of all thanks for doing this really nice QBasic implementation! I realized that the GOTO statement does not seem to be supported, at least when testing it under https://qb64.com/qbjs.html - is this by design or a yet unimplemented command? I know it's not best practice to use GOTO, but it breaks compatibility with programs who nevertheless use it.

boxgaming commented 1 year ago

Hi there and thanks for the feedback! Sorry for taking so long to reply. For some reason I did not see this ticket until now.

At present this is by design. QBJS compiles the basic source code into Javascript. That compiled code is what is executed in the browser. This approach was favored over an interpreter in an effort to achieve near native compiled code performance. Unfortunately, there is no analog in Javascript for the GOTO command. So far, we have not found a way to implement this that would not have a significant negative impact on performance.

One of the major goals of this project is to achieve as much backwards compatibility with QBasic and QB64 as is feasible in a browser-based implementation. I don't see us being able to support GOTO statements in the near term. However, it is something that we will continue to evaluate as the project progresses.

fredlcore commented 1 year ago

Thank you for this in-depth explanation. It is interesting to realize that such a seemingly simple statement such as "GOTO" makes it difficult to implement in JavaScript.

We have had a discussion elsewhere (https://www.facebook.com/groups/2057165187928233/posts/3326038794374193/) about where to draw a line whether a programming language can be called BASIC or not and at least I came to the conclusion that the "GOSUB test" could be an easy yet appropriate way to test this. Because it stands for the fact that BASIC in its original form derived from Dartmouth BASIC did not impose any kind of programming paradigm on its users. You could write rather structured code if you wanted to, but nothing prevented you from making a GOSUB jump from one subroutine to another. Of course such spaghetti code becomes rather unreadable at some point, but the fact that BASIC lets you do that is a key characteristic of the language. And the fact that it is rather complicated to implement in a structured functional or object oriented language seems to underline that point.

Sorry for disgressing here, this should in no way be seen as criticism of your great project here, just some observations that I've made. Keep up the good work and thanks again for explaining the backgrounds here.