GOTO and BASIC considered harmful. Why?

Not sure if this the proper to place this but I'm putting this here for exposure.

Anyway those who are expert programmers and hackers why are both BASIC and the GOTO statement considered harmful? I pretty much know the answer to these questions especially GOTO. I took QuickBASIC classes before and every instructor sternly warned their students that GOTO is banned from use and we will receive a lower grade on the assignments if used.

Personally I agree that both of them are harmful since they make bad habits easier to get and ever harder to get rid of. Although I consider QuickBASIC to be much better then the 8-bit microcomputers I grew up with.

Of the early first 8-bit systems had very little memory and BASIC along with FORTH were among the very few languages that were capable of working on such rather limited hardware at the time.

I think I well abused GOTO when I took a BASIC class in High School using the Apple IIe that we used at the time.

Of course I didn't know any better. I didn't even learn this until I started using Linux.

1 Like

My first entry into programming was gwbasic on DOS4.0 and later an engineer where my wife managed the kitchen handed me a Quick BASIC 4.

QB was a major step because it was an object oriented language.

You could create functions and subs and split your project into modules.

As I remember it branching on conditions in line basic could only be done using goto statements.

As every line was numbered you split your code in huge blocks where the lowest number was the entry point and when the code exited you had to point it back to the exit or point to the next code block. If you forgot to point to the next block it would just blindly continue with the next code line available.

This coding was very quickly labeled spaghetti because navigating such code - literally - was like following boiled spaghetti - you never knew where you would end.

And debugging large chunks of code was next to impossible. It would sometimes take 10 times the time use to write the code to find one bug.

In QuickBASIC you could use GOTO but as you could as easily write a function GOTO was considered bad habit and a no-go.

Later versions of BASIC language still support the GOTO and it is still used with error handling and still it is considered bad habit because your code can branch off and if you don't handle it correct it may not return to the expected code point and thus break application logic.

With newer high level languages like C# and Python - probably others too you have logic to handle it.

In Python - assume the statement is valid and then handle if not using

x = ["item1"]
try:
    something = x[1]
except IndexError as e:
    print(e)
2 Likes

goto is a low level command. Programming languages were introduced to operate on higher levels of abstraction in order to to make life easier for the (human) developers, so it's generally considered bad practice not taking advantage on available high level constructs, because this produces code less maintainable (by a human) and so more error prone.
However in some situations the use of low level commands may exceptionally make sense (usually for performance optimization).

2 Likes

BASIC is not harmful its perfectly fine programming language and very popular for hobby and professional projects. VB .NET is a modern incarnation that is more than capable handling the most complex projects.

GOTO can be harmful but it rarely is. The reason why GOTO is harmful is that using a line number as a point of execution is prone to errors that are very difficult to spot. In practice its very easy to spot with a debugger , because a debugger will take you step by step and it will immediately become apparent that you used the wrong GOTO. Also modern versions of languages do not use GOTO and If I remember correctly even modern of versions of BASIC have removed it as a feature.

It was not BASIC that raised the hysteria with GOTO fear , it was mostly C. In BASIC GOTO rarely became an issue because its very easy to spot in a typical BASIC program which spanned at best a few hundrend lines of code. Using BASIC back then in large project was very hard because as an interpreted language it was very slow and that meant a huge deal for a typical CPU running at 0.004 GHz.

But C thought a great idea to add GOTO, desperately trying to convince its coders is a portable assembler, it only managed to gain very bad reputation because using GOTO on a large code base is asking for trouble. There was an article that heavily criticized GOTO, for very good reason, then hysteria against GOTO that even the original author of the article admitted that his article was taken out of proportion by the GOTO critics.

Even in modern Assembly , the language GOTO originates from, is rarely used in its numeric format and instead it uses labels very similarly to how a function call works.

The evil laugh you hear in the background is GOTO that is so happy coders believe that can get rid of it so easily, in reality a function call can be not as dangerous, but dangerous enough. Wrong function calls are very common in coding but rarely an issue because like GOTO are easily to spot with the help of a debugger but unlike GOTO much less likely to happen.

In reality we can write books of the dangers of bad coding practices without mentioning GOTO. Chapter 1 is always reserved for global variables that are a huge pain to debug even with the most powerful debugger. That is the real enemy, together with short function and variable names and lack of comments.

1 Like

I'm sure modern recent version of BASIC is fine for use by beginning programmers for learning and getting started. The plus side? They all use compilers instead of interpreters.

Forum kindly sponsored by