Imperative vs Functional: Which one to Choose?
summary
Argues that imperative code (familiar, verbose, mutable) adds accidental complexity while functional code is declarative + higher-order functions and reads like the problem statement; demonstrates Java Streams, Collector.joining and a parallelStream gone wrong when a shared ArrayList is mutated (race conditions that “lose Nemo” / broke a mutual‑fund batch). States two purity rules—no visible mutation and no dependency on outside mutable state—and shows exceptions must be modeled as data (Either) not thrown. Recommends prototyping both approaches.
AI-written summary · about
chapters (9)
- 0:00Choosing the right tool
- 3:51Imperative style explained
- 12:10Declarative style approach
- 15:45Functional style defined
- 17:30Benefits of functional style
- 22:50Avoiding programming bias
- 27:06Purity and side effects
- 38:41Handling exceptions
- 50:00Conclusion and prototyping
related talks
45mFrom Imperative to Functional
42mPure Functions and Immutable Objects
48mEmbrace the Func - How Far has Functional Programming Come in Java?
01h 06mThe Joy of Functional Programming
57mTen Common mistakes made in Functional Java
36mHow functional programming change my Java code
01h 31mFunctional Programming in Modern C++: The Imperatives Must Go!
48mFunctional data structures in Java
