Discussion on: OOP vs Functional Programming

rrampage profile image
Raunak Ramakrishnan

FP and OOP mean a lot of different things to different people. This is something to keep in mind while discussing.

Here's why I like FP:

  • Immutable data structures
  • Pure functions (without side-effects) which can be easily tested
  • Building complex software by composing functions
  • Making illegal states unrepresentable using the type system
  • Algebraic data types and pattern matching

There are different types of languages in FP. For example Haskell is lazy by default and this allows you to easily construct some types of programs but makes it much harder to reason about performance. OTOH, Ocaml is an eagerly evaluated language with not as powerful type system as Haskell but it allows to write programs which are competitive in performance with Java and Go.

OOP as envisioned by Alan Kay involves message passing and lightweight programs (like in Smalltalk). What we use in Java and C++ is quite different from his original ideas. That said, I have heard that OOP is useful in GUI programming. Languages like Java and C# have many good properties which make it easier for building large projects with large teams. There are design patterns to efficiently express common idioms.

FP, OOP, Imperative programming, logic programming all have their place in a programmer's toolbelt. Some concepts lend themselves to using one or the other. We should view them as tools to be used as required and not as the one true way of doing things.

lifelongthinker profile image

Great answer. I second every statement. Very important for those interested in the history and understanding of the different paradigms are the people behind these: Alan Kay as a prominent example of where "OOP" originated (a term that Alan himself has never been too happy with).