Hacker News new | past | comments | ask | show | jobs | submit login

Gotos aren't necessarily bad - for example when you have a large amount of nested loops and need to break out of a certain number of them.



this is solved ore cleanly with escape continuation/exceptions.

Perl also provides 'last LABEL', which is handy (lets you break out of any level of nesting).

I guess in a language like C where you can have neither and function calls are slow so the 'return' escape continuation is also unusable there is a reason to use goto for this.


What you really want are continuations.


Overkill. Something really simple like Common Lisp's block/return-from would do...


...built on top of proper continuation support.


Pardon my presumed ignorance, but how is that?


You implement your loop macro such that it binds some variable to a continuation, that when invoked, exits the loop. Then when you want to exit the loop, you invoke the continuation.

(Loop exits, exceptions, returns from functions, etc. are all special cases of continuations.)

This is an improvement over something like Perl's "last LABEL" statement, because you can pass the continuation around and exit the loop from anywhere you desire.


In C/C++ I have longed for a parametrized break statement with value indicating number of nested loops to break at once. I'm sure this goes against some kind of lambda calculus CS ethos though.


Also good for exception/error handling for languages that don't have that capability built in.

E.g. the SQL script I've been working on today has a number of gotos in it.


What you really want are continuations.


I find i can write almost anything never having to use more than two loops.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: