Re: Java needs "goto" (was Re: hi)



Randolf Richardson wrote:

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)

I'm not in the "GOTO is intrinsically evil" camp -- I think it has its uses,
and (if used with discretion, which is the only way that anyone /does/ use goto
these days), can help keep code clean. Mind you, a lot of the reasonable uses
for goto are replaced in Java by try/finally statements; so I'm not sure that
it would actually pay for itself.

But the labelled-break thing is, IMO, even worse than goto could possibly be --
it always seems to make the code confusing. Fortunately, it is hardly ever
used. To be honest, I don't know whether the few times I /have/ seen it used
are confusing because the programmer (having labelled break available) didn't
feel the need to find a clearer structure, or because the underlying task logic
itself was inherently confusing, and a labelled break was the best available
way to express it.


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 think that's technically infeasible given anything like current JVM
implementation technologies.

-- chris



.



Relevant Pages

  • Re: how to emulate goto.
    ... but 'continue break label' is not really a goto. ... developers rather than poor tools. ...
    (comp.lang.java.programmer)
  • Re: Why is GOTO bad?
    ... For people who don't like GOTO, it is an existing real option. ... BREAK label or BREAK n is more flexible working with _ALL_ types of loop. ...
    (microsoft.public.vb.general.discussion)
  • Re: Why is GOTO bad?
    ... BREAK label or BREAK n is more flexible working with _ALL_ types of loop. ... "GOTO label"? ... With break label you can't accidentally jump inside ...
    (microsoft.public.vb.general.discussion)
  • 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: Would like a preprocessor.
    ... goto most often is a sign of a bad programmer ... it and a labelled break is a great place to ... And back on the assembler level, every branch is a goto so ... > don't justify their use in higher-level languages. ...
    (comp.lang.java.programmer)