Udostępnij za pośrednictwem


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

  • Anonymous
    November 11, 2008
    PingBack from http://www.tmao.info/small-basic-and-the-goto-keyword/

  • Anonymous
    November 11, 2008
    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

  • Anonymous
    November 11, 2008
    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.

  • Anonymous
    November 19, 2008
    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.

  • Anonymous
    November 23, 2008
    The comment has been removed

  • Anonymous
    December 15, 2008
    The comment has been removed

  • Anonymous
    December 21, 2008
    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.

  • Anonymous
    January 11, 2009
    The comment has been removed

  • Anonymous
    January 03, 2013
    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.