Java needs "goto" (was Re: hi)



On Wed, 31 Jan 2007 04:55:35 -0800, Lew <lew@xxxxxxxxxxx> wrote:
Lab.Bhattacharjee@xxxxxxxxx wrote:
[sNip]
while (true) {

To depend on exceptions as flow control is a bad practice.
[sNip]

This typically occurs because the reserved word "goto" isn't implemented. There are situations where "goto" would be very useful, such as:

0. An alternative to "break label" since label is currently limited in where it can be located (such code could be easier to read)

1. The ability to share code between methods within a class, which all end with the same functionality (this could be more efficient than calling another method; javac would need to generate errors such as attempts to access variables that belong to different methods, return type mismatches, etc.)

I do agree with your view that infinite loops that depend on exceptions are a bad practice. Using conditionals to trigger a "break" would also be better handled by making that the focus of the loop -- and if they need to compare afterwards, then "do { ... } while (condition);" can certainly solve that problem.

--
Randolf Richardson - kingpin+nntp@xxxxxxxxxxxxxxx
The Lumber Cartel, local 42 (Canadian branch)
http://www.lumbercartel.ca/
.



Relevant Pages

  • Re: Java needs "goto" (was Re: hi)
    ... To depend on exceptions as flow control is a bad practice. ... This typically occurs because the reserved word "goto" isn't implemented. ... An alternative to "break label" since label is currently limited in where it can be located ...
    (comp.lang.java.programmer)
  • Re: What do you think about the code?
    ... Well that's team democracy at work. ... Exceptions are just another form of gotos, ... only its "goto that location and tell the code there that this ...
    (comp.lang.c)
  • Re: What do you think about the code?
    ... Do you program in a language other than C? ... Exceptions are just another form of gotos, ... only its "goto that location and tell the code there that this ... Within a fixed scope, but you still identify the error handler (the ...
    (comp.lang.c)
  • Re: Java needs "goto" (was Re: hi)
    ... Assemblers need "goto" but no decent HLL does. ... I don't use this construction in C either and, again, don't need it. ... Yes - but that's a result of classes that throw exceptions when their methods would be better off returning control values. ... martin@ | Martin Gregorie ...
    (comp.lang.java.programmer)
  • Re: What do you think about the code?
    ... Do you program in a language other than C? ... Exceptions are just another form of gotos, ... only its "goto that location and tell the code there that this ... Anything allocated on the stack will get freed when longjmp gets ...
    (comp.lang.c)