BBC BASIC
« GOTO statement considered harmful »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 4:22pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: GOTO statement considered harmful  (Read 167 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx GOTO statement considered harmful
« Thread started on: Oct 25th, 2017, 11:05pm »

I have been reminded that next year (2018) is the 50th anniversary of Edsger Dijkstra's famous (or infamous) letter "Go To Statement Considered Harmful".  I would like to suggest that every BBC BASIC programmer makes a resolution to stop using GOTO, for good, before then!  I haven't used GOTO in a BBC BASIC program - other than for test purposes - for something like 35 years and I'm sure my programs have benefitted (both in structure and speed) as a result.  You know it makes sense.

Richard.
User IP Logged

MarsFS
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 16
xx Re: GOTO statement considered harmful
« Reply #1 on: Oct 27th, 2017, 09:30am »

I'm reminded of one of the first programs I ever wrote:
Code:
10 PRINT "MarsFS is cool!"
20 GOTO 10 


In terms of trying to learn how programming works I think this type of example is really easy to understand and grabs the attention of someone new to programming.

So for learning and simple programs there really is no harm in using GOTO I think.

For any serious type of application that may be used by other people the programmer should at this level have learned to use more structured conditional blocks and logic to never use GOTO at all.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: GOTO statement considered harmful
« Reply #2 on: Oct 27th, 2017, 1:18pm »

on Oct 27th, 2017, 09:30am, MarsFS wrote:
I think this type of example is really easy to understand and grabs the attention of someone new to programming.

Line numbers? Really?!

I'm of the opinion that the structured alternative is hardly any less easy to understand (if at all) and doesn't have to be 'unlearned' when the newbie tackles more complex programs:

Code:
      REPEAT
        PRINT "MarsFS is cool!"
      UNTIL FALSE 

Richard.

User IP Logged

michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
xx Re: GOTO statement considered harmful
« Reply #3 on: Oct 27th, 2017, 11:31pm »

Quote:
10 PRINT "MarsFS is cool!"
20 GOTO 10


This is how it was done on the TRS-80 and the COCO 3 back in 1982 - 1985.. In fact you couldn't make a savable program to cassette without using the line numbers.

It is nice that BBC4W has all options open. So a programmer who wants to use labels or line numbers or GOTO or GOSUB can do so for what ever reason.

Although, I doubt I would need to use numbers or labels, unless I just had the thought that it might be fun.

BUT THEN ... why not just make a program with a long list of

IF blah%=1 THEN
dothis%=2
ENDIF

One big huge list of that style of programming... No PROC, no FN, no line numbers, no GOTO, no GOSUB.....

AGH !!

I guess if a person wants to do things the hard way they can.

( Actually a person could make a decent program using the IF THEN ... ENDIF scenario, with proper variable management. I would guess it would be much like creating a long thread that would only take actions if conditions were met. )

You would need REPEAT and UNTIL FALSE to enclose the program. Saying no branches were made, no jumps, no FN or PROC..


« Last Edit: Oct 28th, 2017, 06:29am by michael » User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: GOTO statement considered harmful
« Reply #4 on: Oct 28th, 2017, 09:06am »

on Oct 27th, 2017, 11:31pm, michael wrote:
back in 1982 - 1985.. In fact you couldn't make a savable program to cassette without using the line numbers.

Indeed, but the fact that BBC BASIC is 36 years old shouldn't be used as an excuse to write programs now like they were written then!

Quote:
It is nice that BBC4W has all options open.

It's as true now as it was in 1981 that in order to be called BASIC there is a minimum subset of features that must be available, and GOTO/GOSUB - and perhaps also line numbers - are among them. For that very reason there was pressure from some quarters not to use BASIC as the resident language of the BBC Micro but instead a language which 'enforced' a more structured approach (COMAL was favoured by many).

However the BBC felt that, for good or ill, BASIC had become a 'standard' for home computers of the era. There would have been an almightly row if the Computer Literacy Project (i.e. principally the TV series) had taught a language only available on the BBC's own machine. The Corporation would justifiably have been accused of abusing its monopoly to the detriment of commercial companies.

Richard.
User IP Logged

MarsFS
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 16
xx Re: GOTO statement considered harmful
« Reply #5 on: Oct 29th, 2017, 11:28pm »

Quote:
Line numbers? Really?!

To be fair, the first programs I wrote in BBC Basic were on a real BBC Model B so line numbers were not optional.

I quickly learned the perils of over using goto's and in fact our teacher demonstrated many bad examples of how not to use goto.

I still think they are pretty harmless when learning coding, any serious programmer would of course learn better methods. If a programmer has not learned better technique perhaps it is a fault of the person rather than the language or any particular statement.

Reminds me of a quote: "Any fool can use a computer. Many do."
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls