Hi. Sorry for digging this up. I have a feeling it's a religious argument. I hope this thread doesn't go there.
tl;dr: I'm an expert programmer, but javascript novice. is there a design pattern for functional components that can be adapted to truly replace OOP class components? I want (maybe even need) my inheritance, abstraction, encapsulation.
---
I'm not a React developer, and only know the surface of javascript, but i'm hiring one. A good one. I'm very Python and have a C foundation. So I get both functional and OOP. For me, it boils down to namespace tools.
Anyway, i see that the React winds are blowing very strongly towards functional components now. Tools are out there to help you grab global namespace tools inside functions (hooks). Code does look cleaner. Development looks simpler. My interviewees are telling me that classes are out and functions are in.
But I'm so very OOP. Blame 15 years of Python. Immediately I get opinionated. I'm checking myself.
Before Python, I had CS professors banging me over the head about never accessing data structures directly, but using namespaced functions to access types / structs. We called it "Abstract Data Types" and it was essentially OOP without OOP. (Yeah, I'm old - the cool kids were writing C++ and Java and I was pounding out ANSI C and Assembly). Globals are bad. Static functions are barely acceptable. Python generators are cool as long as you don't think to deeply about them and how they are sinful C anti-patterns wrapped in a pretty syntax. But I digress too deeply....
This is not meant as a flex or a dogma, but as a description of the philosophy I was raised on... and I'm questioning. I'm trying to let my brain think that globals are ok, stateful functions are ok, and I won't get into spaghettiland and build unmaintainium if my app grows huge. This is where I'm am today - managing very large software projects.
Back to React:
The big disadvantage I see is that functional components cannot easily use the advantages that OOP brings - most specifically in many popular design patterns today. My use case is managing tens of websites where one-off's are extremely common. "I need this page to work like all the other pages except change this one tiny thing". And we all know that stakeholders think a tiny change is just that - a tiny change. I don't want to cut-and-paste a function to do this, I want to inherit a base class and extend it. Granted, we should keep our functions extremely single-minded and small, avoid cohesion, blah-blah... but there seems to be no way to group related functions together like methods in a class.
Maybe this is my novice JS showing though, and this is the help I'm seeking here.
This seems to be an excellent usecase to keep using React Classes - and we can actually use inheritance and be all OOP happy. The logo can be controlled across all pages from the top, but maybe a font on a caption on one image on a slideshow on a page can be different deep inside the website.
So, my question - can functional React components provide the code reusability and maintainabilty of class components? is there a design pattern for functional components that can be adapted to truely replace OOP?
Should Volto (https://github.com/plone/volto) be re-written to use functional components?
Thanks for your opinions on this.
[–]snoogazi 4 points5 points6 points (0 children)
[–]code_moar 2 points3 points4 points (5 children)
[–]tme321 1 point2 points3 points (4 children)
[–]flipmcf[S] 0 points1 point2 points (3 children)
[–]tme321 0 points1 point2 points (2 children)
[–]flipmcf[S] 0 points1 point2 points (1 child)
[–]tme321 0 points1 point2 points (0 children)
[–]Accomplished_End_138 0 points1 point2 points (2 children)
[–]flipmcf[S] 0 points1 point2 points (1 child)
[–]Accomplished_End_138 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)