Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!comp.vuw.ac.nz!am.dsir.govt.nz!dsiramd!marcamd!mercury!kcbbs!kc From: Gary_Wong@kcbbs.gen.nz (Gary Wong) Newsgroups: comp.lang.pascal Subject: Re: Gotos are ok (Was Re: IMPLEMENT GOT Message-ID: <1991Jan24.112445.3829@kcbbs> Date: 24 Jan 91 11:24:45 GMT Lines: 46 Organisation: Kappa Crucis Unix BBS, Auckland, New Zealand >I can foresee three objections to this code. Let me take them in >order. Okay, I will discuss how I feel with your three objections too: >1) That code isn't efficient. > If the program isn't fast enough, find a better algorithm. If > you can't do that, recode the 1% to 10% of the program where > speed is critical in assembler. But don't use "efficiency" as >an > excuse to put in a goto. I see your point about not using gotos, and I agree that in 90% at least of cases where a goto could be used, it is not the best choice. But rewriting a section of code in assembler to avoid a goto? Once your in assembler, make sure it runs only on a 986 processor which eliminates all JMP instructions and replaces them with FOR, RPT?? I would much rather keep it in pascal (unless its *really* speed critical) and by writing it in assembler you have the problem with it bombing once in a thousand times you mentioned earlier. >2) It uses an extra variable. Well, it doesnt sound like much, but when I come across this situation I'm always annoyed. I realise that I'm worrying too much but I consider the extra space it takes up in the declartion, (even in the exe!!) and I end up using 1 variable to do 2 different things which I know I shouldnt do but i do anyway. But you have to declare a label to use a goto so i guess the variable doesnt make a lot of difference. >3) It isn't really clear. Now this is what I disagree with you about. People have mentioned that gotos make code unclear, so why bother using another solution that makes code unclear? I agree that a goto is not a nice solution to this problem, but yours is not perfect either. Although I have argued about your examples for {not using gotos, I should say that I have come across almost exactly the same situation, many times. And I havent used a goto yet. Also, when writing Pascal I like to know exactly what the code will compile to. By using a goto Im always afraid (I have no idea how valid this is) that Im going to jump over an important section of code like a PUSH or POP - at best, you lose a word of stack space, at worst, the entire stack dies - and that the best solution would be for the compiler to implement a 'Local exit' command (i remember 'exit for' from when i programmed in basic a while back, cant remember exactly how it works) and I think that would be the most elegant solution. Between structured constructs (repeat etc), exit's, and local exits, theres not many cases where a goto would be needed at all. Gary.