Is there a modern programming language which has GOTO function in it? I know basic from a millenia ago and recently learned java, and well I hated OOP, but I could live with it if I had goto.
Name:
Anonymous2007-07-19 23:45 ID:8wGLwsNB
dealing with error situations that don't happen very often, in such a way that the error handling code doesn't clutter up the main code path.
in that case, the code reads like regular exceptions, except all in the same function:
if(error)
goto error_handle
...
error_handle:
~~~
is similar if not almost equal to
if(error)
throw exception_a
...
catch (exception_a)
Name:
Anonymous2007-07-19 23:52 ID:bKSfkdkf
>>41
its C we are talking about here
dealing with errors happens at every single fucking stdlib function call, idiot.
Name:
Anonymous2007-07-19 23:58 ID:0hO7/Wyv
>>41
lol OKAY. Call it throw if it makes you feel so much better.
Name:
Anonymous2007-07-20 1:39 ID:oyT1fTO7
why do c weenies try so hard to come up with some other way to do things that would be much simpler and cleaner if they'd just use another function?
The three statements above form two tight intertwined loops. It's left as an excercise for the reader to rewrite the loops without using gotos. But you'll find that the way it's written above is the most concise and clearest.
>>51
DO YOU FUCKING KNOW ANY C AT ALL YOU FUCKING IDIOT?
for(a; b; c) { d; }
IS
a;
while(b) {
d;
c;
}
YOU FUCKING COCKSUCKER.
>>49,52
AWFUL INDENTATION, NO NEED FOR THESE PARENTHESES STUPID CODE ETC., GTFO.
FUCKING SAGE
Name:
Anonymous2007-07-20 11:50 ID:tNjyyvLd
>>53
indentation was for >>51, i wouldn't normally put it on more than one line like that.
and there are no unnecessary parentheses. && has higher precedence than =.
>>49 and >>52
Wrong. If shift returns true - causing read to be called - the code will call reduce before calling shift again.
Also
-short circuiting and casting pointer to bool is far less transparent than the goto version
-the if statement squeeze in the for loop isn't very readable either
Wrong. If shift returns true - causing read to be called - the code will call reduce before calling shift again. for( tok=getToken() ; shiftTok(tok) ? tok=getToken() : 1 || reduceTok(tok) ; );
-short circuiting and casting pointer to bool is far less transparent than the goto version
the "casting pointer to bool" is just nonsense. a bool in c99 is just an int. and the code in >>45 uses the pointer the same way.
>>64
It is not possible to write this code readably because it has no function.
The code just does 1 2 3 4 or 5 and jumps around.
This is not somthing which can possibly ever occur in real programming because you have an actual task to solve or algorithm to implement, so things are named properly and are done for a purpose.
That can be done easily enough with a simple FSM. It isn't exactly "equally efficient" as your code, but is a great deal more readable (at least to me). Here, the process is broken up into discrete steps which are separate from each other. It is easier to think about the process in terms of how to organize the steps in relation to each other, without having to mess about with what line of code each one is on.
And here's the same FSM but slightly less verbose. I've removed the "else" statements and allowed the cases to fall through each other. This lowers the readability, but uses less code. The readability now becomes more like your original example in >>64 while still requiring no goto statements.
else b() ??? Think you mean else c(). Otherwise, c(), and therefore d() never get called, and your program never terminates if we begin at a(). Though, I think you just typo'd.
Still, ignoring the error, it is functionally equivalent to >>64 , >>66 , and >>67
It would then be a matter of how the code can be optimized when compiling. Other than that it is just a matter of style and there isn't much of an argument either way.
Name:
Anonymous2007-07-22 4:08 ID:61PMylaX
>>73 PROTIP: do1(),do2(),... in most cases are note functions, but blocks of code, using same variables. Good job doing recursion, but it's too much work to send them all to your a(),b(),...
if (err = doOne()) goto oneFail;
if (err = doTwo()) goto twoFail;
if (err = doThree()) goto threeFail;
return 0;
threeFail:
undoTwo();
twoFail:
undoOne();
oneFail:
return err;
}
Yeah, sorry but you can pry my goto from my cold, dead fingers. Exceptions + RAII are a decent substitute for this, but if you're working in plain old C (and for a lot of small to medium scale applications C++ just adds too much baggage), the above idiom works quite nicely for me, ta.
Name:
Anonymous2007-07-22 13:52 ID:AGgx7XQ2
goto makes your computer explode, don't type it. OH SHI-