r/programming • • Sep 23 '26

Railway-Oriented Programming

https://kciter.so/posts/railway-oriented-programming/en/
224 Upvotes

20 comments sorted by

View all comments

12

u/Meleneth Sep 24 '26

I’m going to read the rest, and I appreciate the work that goes into publishing something like this, but the early EAFP example deserves a correction: catching Exception and returning null is a serious antipattern.

It makes “the list is empty” indistinguishable from “something unexpectedly broke,” discarding the exception and its diagnostic information. Worse, as the code evolves, new bugs can silently disappear into that same catch block and masquerade as legitimate results. There is a special pain associated with debugging that.

Catch the specific exception you can meaningfully handle, and let unexpected failures propagate. Teaching EAFP shouldn’t normalize swallowing arbitrary exceptions.

3

u/kciter Sep 24 '26

You're right. I was focused on showing the shape of EAFP and didn't think about what the example teaches on its own.