How to decide what type of programming to use

As the title says, I am wandering how do you guys decide which type of programming paradigm to use. Specifically, I am interested to hear when to use OOP and when to use FP.
I noticed with myself that FP is my default choice, but I want to know how other people make their choice.

PS I am working with MERN stack.

In javascript, it doesn’t have to be one or the other. I find myself using functional components inside objects, or constructing objects that chain together functional inputs/outputs.

Personally, I’ve decided to call myself a FOOP coder. Just to confuse the BEJABBERS out of people. And to make those who aren’t pseudo-intellectual giggle. :wink:

Yeah, I get that. But I was hoping to hear if there are some situations where one is better than another or at the end it all comes down to personal choice.

Sometimes you blend the two, it’s harder to implement OOP concepts in a purely functional language like Haskell and some dialects of Lisp but other functional languages are good and some are hybrids such as Scala and Elixir.

Now, it’s easier to apply functional principles to OOP languages; you see the examples of Java 8> and C# that have stuff like Streams and LINQ, functional Interfaces and delegates, lambda expressions, closures; popular functional libraries with monadic structures such as State, Maybe and Logger/Reader.

I am no expert in when to use which but I just wanted to tell you that sometimes it’s good to just stick to one or the other. I heard somewhere than there’s a reason purely functional high-profile video-games don’t exist or aren’t as successful because video-game design fits so well with OOP. It’s also easy to do naive stuff with functional programming which leads to memory leaks and low-efficiency but surprisingly you can easily detect bottlenecks in your functional code once you become proficient with it.

Clojure is a lisp dialect that is based on the JVM and it means you can use java inter-op whenever you think functional immutable structures (even if we benefit from structural sharing) or constructs might slow down your code.

Functional composition is a huge improvement and is encouraged a lot so I’d advice you to start there; stream-based collection processing is also huge and some languages have the aid of lazy computations. There’s also a term called “transducing” that may help those languages where there is no stream abstraction (like in Java 8 or Elixir) and might help you reduce the performance impact that processes like


might cause (iterating 3 times when you could do it in 1 sweep with streams or transducers).

|> Stream.filter(g)
|> Stream.scan(h)
|> Enum.toList()

This elixir example does it in one sweep, lazily.

Anyway, as I said I’m no expert so I may be incorrect.

Thanks for such a thorough answer. :pray: Btw it’s nice to see a familiar face from the old gitter chatroom days. :slight_smile: