News for hackers. Stuff that matters.
Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by garply on Friday July 31, 2009 @03:11AM (#733944)
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.
Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by nothingmuch on Friday July 31, 2009 @07:03AM (#734144)
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.

Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by jrockway on Friday July 31, 2009 @05:08AM (#734066)
What you really want are continuations.
Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by Hexstream on Friday July 31, 2009 @08:04AM (#734209)
Overkill. Something really simple like Common Lisp's block/return-from would do...
Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by bkudria on Friday July 31, 2009 @04:50PM (#735348)
...built on top of proper continuation support.
Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by arketyp on Friday July 31, 2009 @07:20AM (#734164)
Pardon my presumed ignorance, but how is that?
Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by jrockway on Friday July 31, 2009 @08:17AM (#734227)
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.

Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by arketyp on Friday July 31, 2009 @07:11AM (#734155)
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.
Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by redcap on Friday July 31, 2009 @03:16AM (#733949)
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.

Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by jrockway on Friday July 31, 2009 @07:00AM (#734139)
What you really want are continuations.
Re:Confess HN: Share your Immoral Hacks, Codes or Tweaks by clistctrl on Friday July 31, 2009 @08:04AM (#734210)
I find i can write almost anything never having to use more than two loops.