Live data from Hacker News

Callbacks as our Generation's Goto Statement

tirania.org

221–230 of 287 posts

Re: Callbacks as our Generation's Goto Statement

#221

Earlier quoted context omitted.

Another example: a lot of old code bases use "goto" for error handling. I'm assuming the Linux kernel still does this. Now we've formalized that behavior into exceptions.

You need C++'s RAII idiom or go's defer syntax to get the same behaviour though. I think try-with-resource in Java also would do the same thing, maybe. Just plainly throwing an exception won't release what you've acquired.

Something like go's defer makes most uses of goto (failure handling) unnecessary. However, there is still the "code a state machine" use case for goto.

Re: Callbacks as our Generation's Goto Statement

#222

"Await" is fantastic, and having using it for JavaScript (via TameJS and then IcedCoffeeScript), it makes things a lot easier and clearer. That being said, I don't think the comparison between callbacks and goto is valid. "Goto" allows you to create horrible spaghetti-code programs, and getting rid of it forces you to structure your programs better. "Await", fundamentally, isn't really anything more than syntactic su…

> I don't think the comparison between callbacks and goto is valid.

What is the largest code base you have worked on that used events + callbacks extensively? I worked on a 250,000 lines-of-code Java trading system, and understanding the way the code flow worked from the central event dispatch loop to handler functions, and back to the event dispatch loop took me MONTHS and seriously spoiled the quality of my life (considering how much many hours we spend at work).

Have you used alternative paradigms like Functional Reactive Programming, Promises, etc;? Maybe you don't realize how awesome the alternative is?

Re: Callbacks as our Generation's Goto Statement

#225
Callbacks are a tool in my toolbox. General event based programming is a tool in my toolbox. Various threading models are a tool in my toolbox. Just because there are situations where a tool is not the best choice does not make the tool bad... it means you use a different tool in that case.

Re: Callbacks as our Generation's Goto Statement

#226

The problem is simply that those languages are not Lisp. Once good patterns of use of GOTO were found, it was natural to critisize random uses, and to wrap good uses in a lisp macro. Or in a new while or for "instruction". But then the next construct is discovered, and its bad uses considered harmful, and its good uses need to be wrapped. In lisp, mere programmers will just write the next macro to abstract away this…

Is this a genuine smug lisp weenie post or is it satire?

Re: Callbacks as our Generation's Goto Statement

#227
To appreciate whether callbacks are Goto and what to do about them, it is probably good to read a good perspective on Goto from back in the day: http://cs.sjsu.edu/~mak/CS185C/KnuthStructuredProgrammingGoT...

When skimming it, I noticed the appeal to events and the precursors to literate programming (Knuth eventually came up with literate programming a few years after this paper was written).

Re: Callbacks as our Generation's Goto Statement

#228

Earlier quoted context omitted.

Why do you as an American feel the need to invoke some dead german left-wing militants in a pseudo-religious phrase that's meaningless except maybe for shock value? This seems highly inapproriate for any website and even more so on HN.

(for whatever's worth, I'm Brazilian)

typically American response

Re: Callbacks as our Generation's Goto Statement

#229
post #221

Earlier quoted context omitted.

You need C++'s RAII idiom or go's defer syntax to get the same behaviour though. I think try-with-resource in Java also would do the same thing, maybe. Just plainly throwing an exception won't release what you've acquired.

Something like go's defer makes most uses of goto (failure handling) unnecessary. However, there is still the "code a state machine" use case for goto.

Which we are trying to eliminate with tail-call-optimized mutually recursive functions.

Re: Callbacks as our Generation's Goto Statement

#230
post #226

The problem is simply that those languages are not Lisp. Once good patterns of use of GOTO were found, it was natural to critisize random uses, and to wrap good uses in a lisp macro. Or in a new while or for "instruction". But then the next construct is discovered, and its bad uses considered harmful, and its good uses need to be wrapped. In lisp, mere programmers will just write the next macro to abstract away this…

Is this a genuine smug lisp weenie post or is it satire?

The former. Pascal isn't someone to be trifled with!
Post reply on HN