Viewing a single comment thread. View all comments

2wicky t1_iycqzzr wrote

I remember GOTO in combination with line numbers made maintaining or adding new features in Basic a nightmare. It's hard to tell which lines are being jumped into, meaning that by changing a line of code, you can invertedly break the program flow if you are not paying close attention to any gotos pointing at it.
To avoid this, you avoid changing any existing code that works by jumping around it. All this jumping around then results in a difficult to follow flow.

Using a bad but simple example of spaghetti code:

10 let a = 10

20 let b = "spaghetti"

30 print b

40 let b = "pasta"

50 let a = a + 10

60 if a < 60 then goto a

70 print "code!"

While clever, "spaghetti" shouldn't be printed twice. The right thing to do is rewrite this entire block of code, but you can't really do that if this is part of a larger program with other parts jumping into it as you could risk breaking other parts of your program.
So instead, using the above method of coding around problems, a bug fix could end up looking like this:

10 let a = 10

20 let b = "spaghetti"

30 goto 50

40 let b = "pasta"

50 print b

55 let a = a + 10

60 if a = 20 then goto 40

70 print "code!"

Not very pretty at all.

1