Small Basic and the "Goto" keyword


For the past 40 years, there have been on-going debates in the programming world about the utility and usage of the keyword, Goto.  While it’s been generally accepted that uncontrolled (no pun here) usage of Goto leads to unmanageable and spaghetti code, many, including Donald Knuth, believe that Goto is essential and when used with care will actually lead to clearer and more manageable code.


When designing the Small Basic language, I had the beginner programmer in mind.  Some of them would graduate and move on to other more powerful languages, while some won’t.  Those that won’t, will be content having learned a bit of programming and will remain hobbyists forever.  The addition of concepts to the language had to be very carefully done between these two sets of audience.


For those that are taking the first step into the world of programming, there isn’t an easier and crisper way of teaching branching.  Goto is such a clear and easy to explain this concept that I felt was necessary to include for a beginner.


Now, CS purists would argue that this is setting a bad trend for beginners that might become professional programmers later on and carry with them the bad practice.  I believe that it is better to learn, understand and forget a bad habit than to be ignorant.  Every structured programming language has some version of restricted Goto in the form of break, continue, etc. Understanding that fundamental concept is crucial for professional programmers.  Besides, if they’re graduating from Small Basic, they’re going to run into unrestricted Goto in at least 7 out of the top 10 programming languages.


Coming back to the Small Basic audience, here’s my theory.  Those that are content being hobbyist programmers in Small Basic, don’t really care about the nuances of using Goto.  And those that graduate on to more advanced programming from Small Basic, would be able to appreciate why unrestricted Gotos are “bad.”


PS: Here’s a thread with Linus that I found was interesting.

Comments (9)

  1. Eric Savage says:

    Hi.  We’ve done a review of the Small Basic package on our company blog.  The feedback may be useful to you…

    http://www.chillisoft.co.za/blog/?p=170

  2. Eric Savage says:

    By the way, I personally suspect that the GOTO statement is easier for a beginner to grasp than a SUB.  If the sacrifice of ideals is needed to get somebody in at the front door, then so be it.

  3. Alex says:

    As one who was bought up on Sinclair zx81 basic, aged 14,  with rampant GOTO exposure, learning why GOTO’s are bad marks the first point at which your programming skills go up a gear.

    Reflecting this in your code is the point where you begin to understand the elegance in programming.

    Fondly remembered is a Morse Code tutor I wrote, some twenty lines of code providing the main body of program with every event calling a subroutine.

    Now it was easy to move to VB 3.0 where ‘events’ were real things.

    Without the introduction to programming, the virtue of the ‘goto’ statement is academic.

    Listen to a two year old child talk – almost unintelligeably, 12 years later without issue.

    Everything can come with time.

  4. 猿頁 says:

    再び 米msdn Forum のSmall Basic フォーラムから。 今回はあまり深く考えず、…

  5. leerwerker says:

    Wow,

    I taught programming for more than ten years (long ago) and did not think GoTo was still being discussed!

    We had fairly strict discipline for its use:  we designed programs as an iteration chart, where every frequency of code execution was in a different section – so you were only allowed downward goto’s in a section and never between sections.  

    This way it became a powerful tool and did not lead to spaghetti program design.

  6. rbirkby says:

    Any chance you could put a limit on function size? The biggest issue I see in professional coders without any formal CS training is lack of understanding of modularization in the form of subroutines.

    Unless you think that divide-and-conquer is a difficult strategy to explain to beginners?

    You see, I don’t worry about hobby programmers learning to program in a hobby language. The problems happen when those hobby languages become used in the Enterprise as QuickBasic did.

  7. Pierre says:

    In the program above (fibonnaci), could someone explain me how I can avoid the concept of a "goto" ?

    "goto" are acceptable when pre-conditions and post conditions around the label are simple.

    Isn’t there a goto to the beginning of a program at the start of execution ?

    Where does the program goes when it finishes ? He goes to ….. ahem.  My nephew is asking me bad questions. He must be heretic.

    Pierre

    begin:

    A=0

    B=1

    loop:

    A = A + B

    TextWindow.WriteLine(A)

    B = A + B

    TextWindow.WriteLine(B)

    Program.Delay(100)

    Goto loop

  8. Nathan 43 says:

    I learned on TI 99-4A basic. Cut my teeth with memory manipulation on an Apple IIE and Commodore 64. The day I realized that "GOTO" was not needed was a revelation! Far be it from me to rob another young programmer of that moment.