Composing programs from small simple pieces: OOP vs Functional Programming

Posted by Jay Godse on Programmers See other posts from Programmers or by Jay Godse
Published on 2014-08-24T15:31:46Z Indexed on 2014/08/24 16:28 UTC
Read the original article Hit count: 280

I started programming when imperative programming languages such as C were virtually the only game in town for paid gigs. I'm not a computer scientist by training so I was only exposed to Assembler and Pascal in school, and not Lisp or Prolog.

Over the 1990s, Object-Oriented Programming (OOP) became more popular because one of the marketing memes for OOP was that complex programs could be composed of loosely coupled but well-defined, well-tested, cohesive, and reusable classes and objects. And in many cases that is quite true.

Once I learned object-oriented programming my C programs became better because I structured them more like classes and objects.

In the last few years (2008-2014) I have programmed in Ruby, an OOP language. However, Ruby has many functional programming (FP) features such as lambdas and procs, which enable a different style of programming using recursion, currying, lazy evaluation and the like. (Through ignorance I am at a loss to explain why these techniques are so great). Very recently, I have written code to use methods from the Ruby Enumerable library, such as map(), reduce(), and select(). Apparently this is a functional style of programming. I have found that using these methods significantly reduce code volume, and make my code easier to debug.

Upon reading more about FP, one of the marketing claims made by advocates is that FP enables developers to compose programs out of small well-defined, well-tested, and reusable functions, which leads to less buggy code, and low code volume.

QUESTIONS:

  1. Is the composition of complex program by using FP techniques contradictory to or complementary to composition of a complex program by using OOP techniques?
  2. In which situations is OOP more effective, and when is FP more effective?
  3. Is it possible to use both techniques in the same complex program?
  4. Do the techniques overlap or contradict each other?

© Programmers or respective owner

Related posts about object-oriented

Related posts about functional-programming