When to use which type of programming Paradigm, OOP or Functional Based or Mixture of Both for Front End Javascript
For further actions, you may consider blocking this person and/or reporting abuse
When to use which type of programming Paradigm, OOP or Functional Based or Mixture of Both for Front End Javascript
For further actions, you may consider blocking this person and/or reporting abuse
Alex Booker -
Plain -
Sajad DP -
Prince -
Top comments (10)
I think both is the most practical scenario most of the time. With a flexible programming language use the paradigm that best fits the situation.
In some frontend scenarios it probably does make sense to go hardcore functional though. It will likely be a slower, more complicated building process, but could result in really consistent code.
Love this. Yesterday i wrote my React component with FP implementation and my custom library with OOP implementation to manage local storage and session storage in my web.
Both! For me the control logic is functional whilst representing physical graphical components is OO. I also try to use state machines (Xstate) as much as possible to represent behaviour and sequences of actions. Not sure if state machines are one or the other...
I think in practice a lot depends on who are you working with now or who you might be working with in the future.
Just for yourself? Go nuts using functional concepts if that's what you want.
With a team that's got a lot of experience and knowledge of FP concepts? FP might be a good choice.
With a team of mixed skills, possibly where you don't know who will be hired in the future? Might be worth being more conservative in how you code, OOP, imperative with a sprinkling of functional concepts e.g. map/filter.
Both! When it comes to data manipulation, FP is king. But when you need to encapsulate data and functionality, OOP wins.
E.g.
Say I'm calling an API which returns a list of non-trivial objects. I would wrap the objects with my own class (OOP) so my driver code wouldn't have to touch the data directly. If I'm manipulating the list as a whole, I would use functional array methods (FP).
I'm gonna say 65% OOP and 35% FP. And that estimate is with various languages that I have used in production (JS, PHP, and Python). Going 100% either way is not a very good idea, IMO.
For DOM manipulation, OOP or FP
JavaScript is object functional, use both and move on with life π
Both. But you can switch if it gets more complicated in some modules.
Functional or OO largely depends on what you're trying to do with Javascript or what frameworks you're using.
If argue that it's easier to do functional in React than other frontend libraries.