1. 程式人生 > >Ask HN: Why and how functional programming?

Ask HN: Why and how functional programming?

Lots of questions in this rant. Please bear with me

Coming from OOP paradigm, I am struggling to understand how a FP paradigm can be effectively leveraged in larger systems (should I even try?), especially in ERP systems found in most companies. Such systems have too many external dependencies (libraries and external services), umpteen variations of usecases, and many more coming every day. Often, Java (hugely) or other JVM languages (like scala) are used in such companies. Fitting FP on JVM languages has their own issues. Dependencies cannot be expected to be pure as far as FP is concerned, and this leaks in writing in FP style in multi-paradigm jvm languages. For example, mutation of structures become imminent if we want to optimize code (since JVM compiler doesn't help, or does it?).

I found this talk [1] informative (Functional core/Imperative Shell) for a mixed ecosystem. But maintaining a tight boundary as to what goes in an FP core, and what remains in the imperative shell is difficult to attain.

Problems are compounded by

1. Developer knowledge (not everyone in the team understands FP), and associated steep learning curve.

2. Managing dependencies (a.k.a. Dependency Injection) does not seem to go away in large systems. I have not yet found a clean way to manage these dependencies in a FP paradigm. Have you? (I read about reader monads/kleisli being one way to do so, but seems too much work as compared Dagger, for eg.)

3. Best practices around large FP system, and more so around an FP core within an imperative ecosystem, seem to be still evolving. Are there good resources that I am unaware of?

FYI, I have read Mostly Adequate Guide.

Am I the only one struggling with these issues? If yes, what am I missing, and what can I read/watch to get a clear thought process around these? If not, how do you guys manage such systems if you want to move towards FP?

[1] https://www.destroyallsoftware.com/talks/boundaries