D - goto mess
- Ant (19/19) Dec 02 2003 From a program posted here I could see something like:
- Berin Loritsch (71/93) Dec 02 2003 To be clearer, Java has a bytecode level "goto", but the
- Ant (14/34) Dec 02 2003 I don't like break either...
- Berin Loritsch (5/24) Dec 02 2003 Luckily no. The result I got was
- Vathix (8/27) Dec 02 2003 You're probably referring to my code. I noticed that after I posted it h...
- Ant (16/48) Dec 02 2003 Yes!
- Ilya Minkov (15/41) Dec 03 2003 Oh come on!
- Ant (23/23) Dec 03 2003 goto begin
- Ilya Minkov (3/28) Dec 03 2003 LOL ROTFL!!!!!
- Berin Loritsch (4/6) Dec 03 2003 The JVM only uses goto in the sense of the actual bytecode. It is not, ...
- Lars Ivar Igesund (4/6) Dec 03 2003 No, Java has reserved 'goto' so that it can NEVER be used.
- Ilya Minkov (2/3) Dec 03 2003 Guys, do i really have to mark jokes explicitly ????
- Lars Ivar Igesund (4/7) Dec 03 2003 Sure :) Especially in multicultured environment as this.
From a program posted here I could see something like: if (IAmSmart) { goto itIsTrueIAmSmart } else { itIsTrueIAmSmart: printf("I am stupid!\n); } shouldn't that goto (at least) be illegal? is it supported like that on the languages we are trying to keep some compatibility? Ok, D supports multiple paradigmas, one of which is the stupid paradigma. can we revert that? As you might know java doesn't have goto. It didn't keep it from becaming popular. Ant
Dec 02 2003
Ant wrote:From a program posted here I could see something like: if (IAmSmart) { goto itIsTrueIAmSmart } else { itIsTrueIAmSmart: printf("I am stupid!\n); } shouldn't that goto (at least) be illegal? is it supported like that on the languages we are trying to keep some compatibility? Ok, D supports multiple paradigmas, one of which is the stupid paradigma. can we revert that? As you might know java doesn't have goto. It didn't keep it from becaming popular.To be clearer, Java has a bytecode level "goto", but the semantics of enabling proper goto controls made it so that it was only really safe for the compiler to do. Think about this: while ( keepGoing ) { if ( foo() > someBigSize ) goto notSmart; stack.push( bar() ); } notSmart: baz(stack); what about my stack? Using goto instead of break is messy and not good at all. The supplied example of using goto to circumvent conditional processing is also bad. A worse construct is something like this: class MyClass { int foo() { goto barMeth; return 0; } object bar() { barMeth: printf("Where was this called?"); goto bazMeth; return new MyClass(); } void baz(Stack stack) { if (stack == NULL) throw new IllegalStateException(); bazMeth: // can we still trust the stack variable??? foreach (stack; object obj = stack.pop()) { fprintf("%o", obj); } return; } } Each of these represents bad uses of goto. If we can guarantee that a goto is limited to be *inside* of one function, and it *cannot* override conditional logic, then not only do we remove 90% of the program control problems, we also remove many reasons to have a goto in the first place. If we are talking about exiting a loop early, a break will work. If we are talking about exiting an if/else clause early to the larger method context, then maybe you are doing something that will be difficult to maintain later. The general rule of thumb I use is if you really think you need a goto, its time to rethink the problem. They can introduce more harm than good. The only time that they are really useful is when we are close to the metal. For instance, in byte code generation (or machine code generation) we have the equivalent of a compare/branch type of function. Same thing with the exception handling. Under the hood, the compiler might create something like this: compare( foo() > someBigSize ) bne elseClause // if clause work goto conditionalEnd elseClause: // else clause work goto conditionalEnd conditionalEnd: // other stuff Or with exception handling try // different bytecodes for this //do work goto finallyClause catch // different bytecodes for this // do catch work goto finallyClause finallyClause: // do finally work This is all close the the metal type of stuff, where there are no high level constructs to obviate the need for the goto. It is hard for me to imagine a compelling language that has not gotten rid of the need for goto.
Dec 02 2003
In article <bqihkj$2dp4$1 digitaldaemon.com>, Berin Loritsch says...To be clearer, Java has a bytecode level "goto",Java in the strick meaning: I was referening to the language.what about my stack? Using goto instead of break is messy and not good at all.I don't like break either...A worse construct is something like this: class MyClass { int foo() { goto barMeth; return 0; } object bar() { barMeth: printf("Where was this called?");iykes! is that legal? did you actually compiled it? if so it *MUST* be removed.Each of these represents bad uses of goto. If we can guarantee that a goto is limited to be *inside* of one function, and it *cannot* override conditional logic, then not only do we remove 90% of the program control problems, we also remove many reasons to have a goto in the first place.true.If we are talking about exiting a loop early,As I don't use break there is no such thing. what you call early I just call one of the condition of the loop. If it's too complex perheaps it's again time to rethink the problem (I mean the solution).The general rule of thumb I use is if you really think you need a goto, its time to rethink the problem.very true.The only time that they are really useful is when we are close to the metal.Let's not forget that each program branch is realy a conditional goto. The goto in high level languages is called "if" or "while" or... Ant
Dec 02 2003
Ant wrote:Luckily no. The result I got was $ /dmd/bin/dmd test1.d Error: undefined label barMeth So the label must at least be in the method.A worse construct is something like this: class MyClass { int foo() { goto barMeth; return 0; } object bar() { barMeth: printf("Where was this called?");iykes! is that legal? did you actually compiled it? if so it *MUST* be removed.
Dec 02 2003
"Ant" <Ant_member pathlink.com> wrote in message news:bqieof$29i2$1 digitaldaemon.com...From a program posted here I could see something like: if (IAmSmart) { goto itIsTrueIAmSmart } else { itIsTrueIAmSmart: printf("I am stupid!\n); } shouldn't that goto (at least) be illegal? is it supported like that on the languages we are trying to keep some compatibility? Ok, D supports multiple paradigmas, one of which is the stupid paradigma. can we revert that? As you might know java doesn't have goto. It didn't keep it from becaming popular. AntYou're probably referring to my code. I noticed that after I posted it here; I realized I didn't need a goto there, could have been: if(!smart) makesmart(); imsmart(); But was it any harder to understand?
Dec 02 2003
In article <bqis4n$2su3$1 digitaldaemon.com>, Vathix says..."Ant" <Ant_member pathlink.com> wrote in message news:bqieof$29i2$1 digitaldaemon.com...Yes! see: you where just being lazy and supported by a language that allows you to be lazy. I'm glad you figure that out. no bruised feelings I hope.From a program posted here I could see something like: if (IAmSmart) { goto itIsTrueIAmSmart } else { itIsTrueIAmSmart: printf("I am stupid!\n); } shouldn't that goto (at least) be illegal? is it supported like that on the languages we are trying to keep some compatibility? Ok, D supports multiple paradigmas, one of which is the stupid paradigma. can we revert that? As you might know java doesn't have goto. It didn't keep it from becaming popular. AntYou're probably referring to my code. I noticed that after I posted it here; I realized I didn't need a goto there, could have been: if(!smart) makesmart(); imsmart();But was it any harder to understand?just a bit, but now image instead of 4 lines of code you had 25... and instead of one program with 1000 lines you had 50 programs with 50000 lines... When dealing with a short program that you code in a couple of days you can get throught with anything. If you have to change the program two weeks later you're doomed :) and BTW thank you for the utilities you posted! I'm still thinking of integrating your string class into my D projects. (maybe I'll remove the goto first, just kiding, just kiding :) Ant
Dec 02 2003
Oh come on! Everyone has read the "considered harmful" paper, and i suppose there is much more angst on goto than problems. What the paper referred to, was unstructured BASIC, where there was *no* elegant way of handling many situations, so goto was the only choice. You had the code with a goto every 3 lines or so. I also have some experience of this from my ZX-Spectrum Era, which was when i was 8, 13 years ago. When getting back to coding, i was so frightened of using goto back a few years ago, that i made spaghetty code with some thought-up conditions, which could be cut down by half by a single goto! We have talked this to death. If you are so opposed to goto, don't use it. BTW, i believe JVM supports goto. And the language has it reserved for future use, together with assert. :>>>>>>>>>>>>>>> -eye Ant wrote:From a program posted here I could see something like: if (IAmSmart) { goto itIsTrueIAmSmart } else { itIsTrueIAmSmart: printf("I am stupid!\n); } shouldn't that goto (at least) be illegal? is it supported like that on the languages we are trying to keep some compatibility? Ok, D supports multiple paradigmas, one of which is the stupid paradigma. can we revert that? As you might know java doesn't have goto. It didn't keep it from becaming popular. Ant
Dec 03 2003
goto begin sign: Ant goto exit: warning: I sent the guy a PM but he never replyed got sign begin: gosub greating: (easy joke) I had to say something because goto right: so the C++ guy started crying right: the posted code was realy bad goto good: d rules greating: Hi all, return good: and people was saying good things about it. goto warning: exit:
Dec 03 2003
LOL ROTFL!!!!! :D Ant wrote:goto begin sign: Ant goto exit: warning: I sent the guy a PM but he never replyed got sign begin: gosub greating: (easy joke) I had to say something because goto right: so the C++ guy started crying right: the posted code was realy bad goto good: d rules greating: Hi all, return good: and people was saying good things about it. goto warning: exit:
Dec 03 2003
Ilya Minkov wrote:BTW, i believe JVM supports goto. And the language has it reserved for future use, together with assert. :>>>>>>>>>>>>>>>The JVM only uses goto in the sense of the actual bytecode. It is not, nor ever will be, a usable keyword in Java. Assert OTOH is a keyword that is enabled.
Dec 03 2003
"Ilya Minkov" <minkov cs.tum.edu> wrote in message news:bqlfme$k7k$1 digitaldaemon.com...BTW, i believe JVM supports goto. And the language has it reserved for future use, together with assert. :>>>>>>>>>>>>>>>No, Java has reserved 'goto' so that it can NEVER be used. Lars Ivar Igesund
Dec 03 2003
Lars Ivar Igesund wrote:No, Java has reserved 'goto' so that it can NEVER be used.Guys, do i really have to mark jokes explicitly ????
Dec 03 2003
"Ilya Minkov" <minkov cs.tum.edu> wrote in message news:bqlk2l$q74$2 digitaldaemon.com...Lars Ivar Igesund wrote:Sure :) Especially in multicultured environment as this. Lars Ivar IgesundNo, Java has reserved 'goto' so that it can NEVER be used.Guys, do i really have to mark jokes explicitly ????
Dec 03 2003