When we code, we tend to focus on the ‘happy path’. But in the real world, our application has to deal with validation, logging, network errors, and other ‘un-happy paths’.
The good news is that we know about these different paths: we know that validations may fail and we know that network requests may not come back. Railway-oriented programming is an approach that makes sure we think about and handle all these possible outcomes.
In our team, we were programming in a railway-oriented style before we discovered it has a name. Today, we are fully aware of and embrace this approach in every PR we make. Thanks to this, our services are very robust.
Railway-oriented programming is a term coined by Scott Wlaschin, who talks and writes about it using F# language. I will show how we in our team write it in TypeScript with the help of a library called fp-ts.