-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
  • 19
  • 4
  • If you are looking for "features" or "characteristics" of a system that make one or another paradigm a better choice, then I suggest removing any reference to _"what would be my | anyone else's choice"_. My choice, as @DocBrown well-say, it's the one I know better. Even if it's the most inefficient and unsuitable of the two. – Laiv Nov 24 '22 at 12:41
  • @Laiv I have edited the question – Dennis Nov 24 '22 at 12:44
  • The person who invented the term "Object-oriented" would disagree with your definition: https://softwareengineering.stackexchange.com/questions/46592/so-what-did-alan-kay-really-mean-by-the-term-object-oriented -- his original definition of "OO" is really a lot closer to your definition of functional programming. (Alan Kay has commented in one of the answers to that thread making it clear that "object-orientation" is about messaging, not about objects or state) – Ben Cottrell Nov 24 '22 at 14:55

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
  • 199,015
  • 33
  • 367
  • 565
  • Hm. I was about to say "the one you master", but I thought it was too... simplistic? If we could remove "knowledge" from the equation, the question boils down to _"what are the characteristics of a system that makes one or another paradigm more suitable for the job"_ – Laiv Nov 24 '22 at 12:38
  • @Laiv: I was tempted to write "The one your team likes best". But looking for technical characteristics here is exactly what I think is far from reality. – Doc Brown Nov 24 '22 at 12:40
  • I just want to know the tradeoffs between these two styles. In which case using OOP makes sense and vice versa. – Dennis Nov 24 '22 at 12:41
  • @Dennis: yes, and I would answer "you are asking the wrong question". But FWIW, have a look at https://softwareengineering.stackexchange.com/questions/163432/is-functional-programming-a-superset-of-object-oriented - maybe it helps you to understand why. – Doc Brown Nov 24 '22 at 12:42