News for hackers. Stuff that matters.
Re:Railway oriented programming by brian_cloutier on Thursday June 23, 2016 @03:47AM (#11959440)
Every single control flow tool you've ever used is in essence a goto. Every conditional, every loop, every function call. Many modern function calls are in some respects _worse_ than gotos ever were, you don't even know which code you're going to jump to.

It's not goto's that were so painful, it was unstructured gotos. Calling exceptions gotos is not a reasonable criticism. They have some very well-defined structure, and additional benefits like separating your happy-path code from your error-handling code, making both simpler.

Re:Railway oriented programming by mafribe on Thursday June 23, 2016 @05:36AM (#11959774)
It's important that there are two very different approaches to control flow manipulation. They differ in when the target of a jump is bound.

- Static binding of location to jump to. This is what goto, callcc, while, for etc. do.

- Dynamic binding of location to jump to. This is what exceptions do.

You can show that they are really different, in the sense that (in the absence of powerful language features), they cannot simulate each other, see [1]. Once you realise that exceptions and gotos are quite different thinking about error handling becomes more clearer.

[1] J. G. Riecke, H. Thielecke, Typed Exceptions and Continuations Cannot Macro-Express Each Other.

Re:Railway oriented programming by hvidgaard on Thursday June 23, 2016 @06:52AM (#11960053)
I accidently hit downvote on your post, and I cannot undo it. I hope some kind soul will upvote you to counter. Your post has solid information for the topic at hand.
Re:Railway oriented programming by brian_cloutier on Thursday June 23, 2016 @07:09AM (#11960120)
That's a really cool result, thanks for pointing it out!
Re:Railway oriented programming by hvidgaard on Thursday June 23, 2016 @06:48AM (#11960026)
The comparison to goto was not meant as criticism, but because both disrupt the control flow in a way that has no structure. Conditionals, loops, and calls do have structure, they are the flow.

When a language support contructions such that normal control flow event are either "success + result", or "failure + error", it's much easier to follow, for me, and experience has taught me that it is far less error prone. Exceptions have a use for things that are unexpected, but happened anyway, such as OutOfMemoryException.