-2

Which paradigm(between OOP and Functional) should be chosen for a given task ? What are the tradeoffs between these two styles ? In which case using Functional makes sense and vice versa,in which case OOP should be used ?

we all know,

  1. OOP: As the name suggests, when designing a system with object-oriented programming, you’re thinking about organizing your system as objects that have state and may change over time.

  2. Functional: Functional programming, on the other hand, is all about inputs and outputs; that is, viewing your system as functional “black boxes” that are given inputs and return outputs that can then be given as inputs to other black boxes, and so on and so forth. For that reason, if your system has lots of streams of data that you want to transform, functional programming might be the way to go.

I want to know the tradeoffs between these two styles,In which case using Functional makes sense and vice versa,in which case OOP should be used ?

Dennis
  • 25

1 Answers1

4

Your question is somewhat like asking which instrument a musician should choose (for example, a flute vs a violin) to entertain their audience.

Hence, the only honest answer which will really meet reality is:

Choose the paradigm your team knows best.

If a particular task is solved quicker by a programmer in a more OO fashion or a more FP fashion depends mainly on what they are most proficient in. Note also, though OOP and FP are not completely orthogonal, they are also not mutual exclusive, and in most well-structured programs of a certain size you will typically find OO elements as well as FP elements.

Of course, in 9 of 10 real-world software engineering tasks, you are building something as an extension or change to an existing system, so it is likely you have to take into account which programming languages and architecture fits to that system. But assumed the team who gets the task to evolve the system contains the same devs who were maintaining that system over the last years, the answer above still applies.

Doc Brown
  • 218,378