GOTO without GOTO

SYS 64738
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

GOTO without GOTO

Post by Shaun_B »

Messing with FOR loops counters might not be considered good practise in general programming, but in BASIC you can do some good things. Like using it as a do...while equivalent, you can also use it like a while (true) { // code } or while (1) { // code } as follows:

Code: Select all

0 for i=0 to 1
1 print chr$(205.4+rnd(.));
2 i=0: next
The trivial example aside, it means no GOTO statement.

Regards,

Shaun.


BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
User avatar
e5frog
Member
Member
Posts: 84
Joined: Sun Apr 13, 2014 8:04 pm
Location: Sweden
Contact:

Re: GOTO without GOTO

Post by e5frog »

Sure, but why?

0 printchr$(205.4+rnd(.));:run
My other hobby: Image
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: GOTO without GOTO

Post by Shaun_B »

e5frog wrote:Sure, but why?

0 printchr$(205.4+rnd(.));:run
Or, if you like:

Code: Select all

0 ?chr$(205.4+rnd(.));:goto
Will definitely work on the C64 and VIC-20.

But the point wasn't what was happening, but just how you can do an unconditional loop without the GOTO statement. Okay, it has limited uses unless, but I've found some.

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
User avatar
e5frog
Member
Member
Posts: 84
Joined: Sun Apr 13, 2014 8:04 pm
Location: Sweden
Contact:

Re: GOTO without GOTO

Post by e5frog »

We saw some examples of that in the "No GOTO"-competition on REMOVED, but what's the point of it, is there a gain compared to using a goto? Shorter code, I think not. Is it faster? Possibly??
My other hobby: Image
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: GOTO without GOTO

Post by Shaun_B »

e5frog wrote:We saw some examples of that in the "No GOTO"-competition on REMOVED, but what's the point of it, is there a gain compared to using a goto? Shorter code, I think not. Is it faster? Possibly??
You have many ways of solving the same problem in all problem-orientated programming languages, using GOTO is considered bad practise nowadays (and has been since the 1970s actually because it leads to 'spaghetti code'), and does not exist as a keyword in some languages (or at least I can't find a reference to it).

I don't mind how something is done to be honest as long as it does what it's supposed to. A GOTO-less BASIC program is as much of an intellectual challenge as anything else, especially as you will likely approach the problem differently.

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
User avatar
e5frog
Member
Member
Posts: 84
Joined: Sun Apr 13, 2014 8:04 pm
Location: Sweden
Contact:

Re: GOTO without GOTO

Post by e5frog »

Seems like you'd find one way to achieve the same result and you'd just use that everywhere you would have used goto - if it's needed.
I guess JMP in assembler is also bad then - as it's basically the same thing.

Is GOTO considered bad practice, in retro computing, by whom? I've heard it before, who said it and why is that? Isn't all available commands in the programming language you're using allowed?

EDIT: Seems it's a personal opinion of Edgar Dijkstra - why should we care? It also applies to modern object oriented languages.
My other hobby: Image
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: GOTO without GOTO

Post by Shaun_B »

e5frog wrote:Seems like you'd find one way to achieve the same result and you'd just use that everywhere you would have used goto - if it's needed.
I guess JMP in assembler is also bad then - as it's basically the same thing.
No, because at the lowest level, unconditional jumps are sometimes unavoidable. High level languages are for humans, so the Spaghetti code argument prevails. I'm not saying I agree one way or another, but it's what my professors have told me over my studies since 2009. Who's to argue with a computer scientist, eh?
Is GOTO considered bad practice, in retro computing, by whom? I've heard it before, who said it and why is that? Isn't all available commands in the programming language you're using allowed?
It's also still available in C, C++ and, last October, someone on my MSc used it in C# - I didn't realise that you could? Unless they were prototyping their code in C when the lecturer looked over their shoulder.
EDIT: Seems it's a personal opinion of Edgar Dijkstra - why should we care? It also applies to modern object oriented languages.
It's also a consensus amongst all of the developers that I know (I work as a developer and have met a lot of developers through my work with Micro Mart and other magazines), and all of the programming lecturers that I've studied with. Which is why ActionScript isn't considered a nice language and no full-time developer likes using it.

There are two rules that apply here: if you have to ask why, then it might not be for you. If you have to ask why again after a fairly reasonable explanation, then it's not for you. I could ask why my girlfriend enjoys shopping (especially clothes shopping), but it is futile in doing so.

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 4 guests