Page 2 of 6

Posted: Thu May 11, 2006 1:05 pm
by Dare2
:D

Your round, Pupil!

Posted: Thu May 11, 2006 1:09 pm
by netmaestro
Actually I use GOTO quite a bit in debugging as typing a label and a GOTO is quicker than commenting out a whole block of code if I want to skip over it to see why the latest Dare2 suggestion broke my code :twisted:

Posted: Thu May 11, 2006 1:10 pm
by Dare2
:lol:

Posted: Thu May 11, 2006 10:45 pm
by dioxin
There's nothing wrong with using GOTO or GOSUB, they're very useful at times.

If you end up with bad code, don't blame the GOSUB, blame the programmer.

Paul.

Posted: Thu May 11, 2006 11:08 pm
by jack
Pupil wrote:Most anything you need to use Gosub for can easily be replaced by a procedure which imho improves readabillity alot. However on the subject of GOTO, i can't really understand all the rabid goto haters, you've been brainwashed by your teachers ;) If you avoid goto at all cost you should logically avoid Break and Continue as well, because they're just Goto's in disguise ;)
agree 100% :D

Posted: Fri May 12, 2006 2:29 am
by Phoenix
jack wrote:
Pupil wrote:Most anything you need to use Gosub for can easily be replaced by a procedure which imho improves readabillity alot. However on the subject of GOTO, i can't really understand all the rabid goto haters, you've been brainwashed by your teachers ;) If you avoid goto at all cost you should logically avoid Break and Continue as well, because they're just Goto's in disguise ;)
agree 100% :D
A very good point!!!

Posted: Fri May 12, 2006 3:07 am
by Joakim Christiansen
Pupil wrote:If you avoid goto at all cost you should logically avoid Break and Continue as well, because they're just Goto's in disguise
I don't agree :P
If you avoid break and continue it would just make your code slow and stupid :D

Code: Select all

ForEach(Person())
  If Person()\Name = "Timmy"
    MessageRequestor("Yeah!","Timmy was found!")
    Break ; <-- We need a sexy break here because we found Timmy and we can stop searching now!
  EndIf
Next

Posted: Fri May 12, 2006 7:57 am
by WytRaven
Joakim Christiansen wrote:
Pupil wrote:If you avoid goto at all cost you should logically avoid Break and Continue as well, because they're just Goto's in disguise
I don't agree :P
If you avoid break and continue it would just make your code slow and stupid :D

Code: Select all

ForEach(Person())
  If Person()\Name = "Timmy"
    MessageRequestor("Yeah!","Timmy was found!")
    Break ; <-- We need a sexy break here because we found Timmy and we can stop searching now!
  EndIf
Next
I believe you just missed the point.

Play around learning some assembly language..."goto"s are used constantly.

Posted: Fri May 12, 2006 12:13 pm
by MikeB
I don't think I have used a GOTO or a GOSUB since starting with PB. I used to use them with BLITZ on the Amiga before changing to assembly, which was the only way to really get the Amiga going. (Assembly language on the PC is beyond me). However to get back to the subject, I agree that GOTO's can turn your code into spaghetti, but as far as I can see there is little to choose between procedures and GOSUB's except for the fact that passing parameters to a procedure is much neater than using subroutines. Getting results back are much the same except where you only want one return which is obviously easy with a procedure and needs use of variables with a subroutine, as does a procedure for more than one. Otherwise I think that a procedure being called in the same way as a normal command makes for uniformity. Of course now with Macros small GOSUBs are redundant.

Posted: Fri May 12, 2006 12:21 pm
by Hades
I haven't ever used Continue and I try to avoid Break, but sometimes there's no real option.
But IMO Break and Continue are very different to Goto. It is clearly defined where they go. They are part of a loop, Select or something like that.
In every control structure (If, Repeat, While...) in ASM, there is at least one jump to a label, like with Goto. So you want to say because of that it's all the same?
No! They all have a clear start and a clear end. Goto hasn't. With Goto you can jump everywhere without limits. That's the difference. And that makes the code hard to read and maintain.

And Gosub is just a poor man's Procedure call. I don't see any reason to use it.

Posted: Fri May 12, 2006 2:49 pm
by Pupil
Hades wrote: But IMO Break and Continue are very different to Goto. It is clearly defined where they go. They are part of a loop, Select or something like that.
I strongly disagree, your logic is somewhat lacking, why? -Because you explicitly tell to which label you will go with a GOTO so it's not undefined or badly defined, it's the opposite, it's clearly defined as is the case with break and continue.
Sometimes i think that it's even harder to find out what you are continuing or breaking out of if you have several nested If:for:while:repeat:select structures that cover more than can fit on a screen at one time, than finding where a label is!
Hades wrote: In every control structure (If, Repeat, While...) in ASM, there is at least one jump to a label, like with Goto. So you want to say because of that it's all the same?
No, thats not what i'm saying(i do realize that this might not be directly aimed at me, but i'll aswer anyway ;)), there's also a significant difference between If, Repeat, While etc and Break, Continue -they have a counter part, Break and Continue don't so you can't relly group them together like that IMO.
Hades wrote: With Goto you can jump everywhere without limits. That's the difference. And that makes the code hard to read and maintain.
I agree that the scope is one thing that makes them different.
However when i use GOTO it's often withing a limited part of the code so for me it's not hard to read or maintain. I also find that sometimes you make the code more unreadable if you at all cost avoid goto and use a multiude of nested If's or whatever to get around what could easily be solved by using a goto.

@Joakim Christiansen

Code: Select all

ForEach(Person())
  If Person()\Name = "Timmy"
    MessageRequestor("Yeah!","Timmy was found!")
    Goto lbl_endsearch ; <-- We need a sexy break here because we found Timmy and we can stop searching now!
  EndIf
Next
lbl_endsearch:
:P

Posted: Fri May 12, 2006 4:12 pm
by Hades
Sure, the Goto will go to the label. Would be a bit difficult do write a program if it would go where it wants to. :roll:

But where is that label? You have to search for it. Easy for a few lines, horrible for a big project.

I've learned Basic on a VC20 in the early 80s. So I was coding with Goto's and Gosub's for many years. But I'm happy it's a thing of the past (at least for me).

I have no problem with you using Goto and Gosub. Do what you like. But it doesn't make it good coding style.

Posted: Fri May 12, 2006 4:54 pm
by Pupil
Hades wrote:Sure, the Goto will go to the label. Would be a bit difficult do write a program if it would go where it wants to. :roll:

But where is that label? You have to search for it. Easy for a few lines, horrible for a big project.

I've learned Basic on a VC20 in the early 80s. So I was coding with Goto's and Gosub's for many years. But I'm happy it's a thing of the past (at least for me).

I have no problem with you using Goto and Gosub. Do what you like. But it doesn't make it good coding style.
Just saying -you use GOTO ergo you're coding style is bad- is a bit to simple, it's like saying -your shirt is wrinkly, your home must be very untidy- (That's about the same leap of assumtion that you do :))

I'm not saying that the use of GOTO can't/won't mess things up, however bad coding style can and will mess any code up, be it with GOTO or without..

Posted: Fri May 12, 2006 5:01 pm
by Joakim Christiansen
All people using GOTO's are gays!! :P

Posted: Fri May 12, 2006 5:01 pm
by Hades
@Pupil

Using Goto at all is bad coding style. That's all I wanted to say. You don't have to agree.
It's like I said: Do what you like.