Re:Ask HN: How do I feel less guilty about bugs?
by deltaoneseven on Monday March 07, 2022 @11:27PM
(#30596447)
Agreed, but I would go further to say that the type system and immutability helps in the area you describe as well: "or where you failed to predict some sequence of actions and account for it correctly."
Basically immutability serves to create more invariants and reduce complexity of the program such that it is much more predictable.
I'm advocating exactly your conclusion hence the reason why I specified that immutability is the keyword, not monads and other advanced concepts associated with functional programming.
It's better to focus on clear and simple code styles and architectures. The goal is that when you're debugging the code or explaining it to someone else, you don't want any situations where things don't make sense, or something happens in a weird order for no apparent reason. Immutability can help here, for sure, but FP is a double edged sword. Sometimes it's fantastic but at others it makes your code into an unintelligible mess.
So yeah: Don't go rushing to rewrite your perfectly functional Java/Ruby/Python app across to Haskell or Clojure. It won't help you much at all. Rather, think about how you might use some of the ideas like immutability and function composition, to make your Java/Ruby/Python app easier to work with.