swlaschin / RailwayOrientedProgramming

Railway Oriented Programming slides and code
92 stars 11 forks source link

Railway vs. Exceptions #3

Open dlazerka opened 3 years ago

dlazerka commented 3 years ago

Hi Scott,

It's more of question than an issue.

I couldn't stop thinking that with propagating error results using railway, we're basically reinventing exceptions. With two main differences:

Can we get our stacktraces back with Railway? The only way I see is to have "cause" field at each exception, and wrap them errors manually before returning (with some custom differentiator aka "line number").

swlaschin commented 3 years ago

I agree with your points! In fact I wrote a whole post about when NOT to use Results :) https://fsharpforfunandprofit.com/posts/against-railway-oriented-programming/

In short, use Result for domain modeling and use exceptions if you need diagnostics. Hope that helps!