shame there is no goto command
Monkey Forums/Monkey Programming/shame there is no goto command
| ||
maybe its not concidred professional. but now that im taking a code from blitz3d and trying to remake it in monkey, the lake of goto command makes the translation a harder task. what was so wrong with goto command that it hadto be eliminated from monkey? did i missed something. |
| ||
Goto is evil! It makes spaghetti code, which is hard to read and follow. Funtions and classes make code so much more readable. |
| ||
No, it's not a shame at all. Seeing "goto" in code makes my head asplode. If you find yourself needing a goto, you need to rewrite your code. |
| ||
Monkey translates to native source code. An as, cpp, java, javascript... all of them don't support GOTO. So if Mark would have wanted to implement such a thing, it would not be possible. |
| ||
Maybe monkey/programming isn't for you. all you ever seem to do is complain about everything. |
| ||
object oriented programming eliminate the need of using goto. I only used goto in assembler and even with that it made my life miserable. It is so easy to mess things up, hard to debug, hard to read, and not considered good programming at all. MikeHart, cpp does have a goto command but nobody uses it. I think earlier versions of Java used it too. Because it is still reserved but cannot be used. |
| ||
But how will we ever do:10 print "goto sux" 20 goto 10 ??? |
| ||
Goto? Gosub is way better... :P |
| ||
@Aman... pst don't tell him, or he wants it to be implemented. :-) |
| ||
Dont tell me whats for me and whats not GfK. Im a complainer allright. Thats true. Goto aint professional Ive always knew that. But its an old habbit I need to get rid off. I can easly live without it I guess. just the translation from Blitz3D will become harder. Or I will what I need from scratch. Im sure mark.s knows what he is doing and I love monkey prog.. I just need to get used to more pro launaguages because my background is only Blitz3D if its not clear up till now. |
| ||
MikeHart.. Haha I will now Goto Cpp forum and demend to Implant Goto! :-) |
| ||
Show us the Blitz3D code you want to convert and we'll help you translate it to Monkey. |
| ||
I do have found memories of organising code by line number and deciding after writting hundereds of lines of code that i needed to infact have more line numbers inserted! .. oh what fun that was! |
| ||
Thanks therevills. Its not that I dont know how, its just gonna be a little bit harder to convert it. Its some kind of a Database controller that I need for saving purposes and im using line parsing and reqursive functions. All my goto's were only inside Functions and not in the main code. Im really glad to git rid of Goto if its really concidred bad programing. |
| ||
If they are in a function, then you can easily use it as an if statement, if you jump down, or a loop statement if you had jumped upwards to a label. Examples: 'Goto jump downwards------------------ Function foo() If a=b Then goto label1 a=b label1: b=0 End 'replaced by if statement Function foo() If a<>b Then a=b Endif b=0 End 'Example goto jump upwards Function foo() label1: a+=1 If a < 10 Then goto label1 End 'Becomes a repeat until loop-------- Function foo() Repeat a+=1 Until a= 10 End |
| ||
But how will we ever do: While true Print "goto sux" End While Goto aint professional Ive always knew that. It's not really a matter of "being professional". There are probably hundreds of professional programmers who use goto every day. Instruction set wise it's simply a branch instruction to the CPU, just as a function or method invocation.So why do so many people consider goto a really bad habit? Because they work in languages where it is unnecessary, and more importantly, can break the call stack, leading to bugs and random crashes that are next to impossible to debug. Essentially goto is only evil if stability and maintainability is important to you. Thankfully 25 years of being forced to use Microsoft products has given the general public a low tolerance for software that is buggy and obsolete. Im really glad to git rid of Goto if its really concidred bad programing. It is "Considered harmful". You can read the original paper on why, if you really want to know more. |
| ||
seems i had a lot less goto's in my blitz3d code then i expected. therefor converting will be easyer then i predicted. |
| ||
It would be nice to be able to exit from a Select block. |
| ||
Simple workaround for exit from "Select":Function SelectMe:Int(aa:Int) Select aa Case 0 Print "0" Return 0 Case 1 Print "1" Case 2 Print "2" End Select Print ("Select at End") Return 0 End Function Main() SelectMe(1) SelectMe(2) SelectMe(0) End Result: 1 Select at End 2 Select at End 0 |
| ||
What I meant was I'd like to have: Select aa case 1 If ( condition ) Exit DoStuff() case 2 DoOtherStuff() End Of course it's easy to implement with If statements but it would be nice to have a quick exit available. |
| ||
Function SelectMe:Void( v%, x% ) Select v Case 10 Print "Test" If x = 11 Then Return Print "You can see me only if x <> 11 xD" Case 11 ..... End Select End Function |
| ||
Gerry, do you mean exit, like the break command in C. The parser automatically detects it as each new case starts and won't run through the other cases. Besides that, it converts the select statements to if statements in the output, so there's no chance of it running through them anyways. There was a topic on it a bit ago: http://monkeycoder.co.nz/Community/posts.php?topic=1001 Also, this will do what you wanted above Select aa Case 1 ' This will run the function if the conditions are not met If ( Not condition ) Then DoStuff() Case 2 DoOtherStuff() End HTML5 output, for instance, will be something like this var bbt_aa = 1; var bbt_ = bbt_aa; if( bbt_ == 1 ) { if( !condition ) { DoStuff(); } } else { if( bbt_ == 2 ) { DoOtherStuff(); } } |
| ||
Exactly, I just would like a break statement! I know Monkey does not fall through Case blocks anyway, but sometimes it makes the logic a little clearer not to have to write:Case n If ( Not condition ) DoStuff() End It's a small thing and I'm not breaking my heart over its absence. I suppose some would also argue that not having it gives you the option of using Select to decide whether to exit from a For or Do loop that encloses the Select statement! |
| ||
I was actually wishing for the same thing in BlitzMax recently, wanting a way to conditionally exit before running the rest of the code in the selected case, ie.thing = 1 something = 1 Select thing Case 1 If something Then Exit ' Or Break... NotDoingThisNow () OrThis () DefinitelyNotDoingThis () AndAsForThis () Case 2 Etc () End In my case it was mainly to get out early to avoid processing a ton of data while I was testing to see what cases came up where. (JPEG file parser, reading unfamiliar data.) |
| ||
Isn't "Exit" the Break break statement? |
| ||
happy to get rid of goto (i think) |
| ||
Well, it's up to Mark. I guess he will probably take the view that changing it now will break existing code, and it's not important enough for that. (A workaround would be to have a special syntax such as "Exit Select".) On the subject of Goto, I say give us the gun and let us decide whether to fire it. Personally I almost never use it, not so much even from fear of spaghetti code as the simple ugliness of code with labels sticking out from the flow! Still, you can never be sure it will not sometimes be the best of some bad options. |
| ||
Monkey is an OO language and Goto does not have any place in an OO language. |
| ||
Ohhhhh |
| ||
The OP is trolling for responses on this. There is no reasonable need or want for a GOTO statement in any programming language these days. |
| ||
I Agree! now im going to eat.. |
| ||
After you eat how about you go code? If you don't I swear to lucifer you will burn! Also, if none of you finish your games............the bunny gets it. |
| ||
DruggedBunny - you can cheat it like this in BlitzMax:Strict Local thing:Int = 1 Local something:Int = 1 #blah Repeat Select thing Case 1 If something Then Exit blah Print "here" Case 2 Print "never here" End Select Until False 'exit to here Print "here2" End |
| ||
I code all the and all night . here is the sum of all my longtime work... 10 Print"Hardcoal" 20 Goto 10 Thats a results of a hard work of at least 10 months of coding and debugging. my mom is really proud of me right mom? mom?? mom?? |
| ||
The OP is trolling for responses on this. There is no reasonable need or want for a GOTO statement in any programming language these days. Except first and second generation programming languages. Like Assembly or Shaders. |
| ||
Actually GOTO can still be quite handy on error handling and recovery situations. |