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



Randolf Richardson wrote:
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 disagree, I think goto was dumped for very good reasons, and structured programming (i.e. no gotos; use methods and refactoring techniques instead) makes a lot more sense.


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

  • Java needs "goto" (was Re: hi)
    ... This typically occurs because the reserved word "goto" isn't implemented. ... I do agree with your view that infinite loops that depend on exceptions are a bad practice. ...
    (comp.lang.java.programmer)
  • Re: Debugging standard C library routines
    ... In particular such declarations are ... Not for people who avoid goto like the... ... You seem to be saying that, IF I adopt one particular coding practice that I ... a goto makes my code clearer to me than a more structured approach, ...
    (comp.lang.c)
  • Re: Using GOTO
    ... most developers feel using GOTO is not a good ... Where the AttemptToReadFile method opens a file and attempts to read it, ... Another place I see value is in complicated loops, within loops, when you ... > Is it good practice using GOTO in .NET application? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Should function argument be changed in function body?
    ... Chris Croughton writes: ... >> In practice it sounds like our views are actually pretty ... that I think of using goto. ...
    (comp.lang.c)
  • 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)