DEV Community

Are OOP Methodologies and Patterns Dead for Frontend Development?

Fedor on January 11, 2024

Is the Age of Object-Oriented Programming (OOP) and Traditional Patterns Over in Frontend Development? Let's Dive In. Frontend development has und...
Collapse
 
efpage profile image
Eckehard

See this post: Paradigms are not religion. You don't have to be either Catholic or Protestant....

I belive that the whole discussion of OOP vs FP is completely useless. People should use whatever serves best for them, not what others tell them is the new religion.

I´m using functional patterns if they are helpful, but if you try follow this paradigm in Javascript for simple things like loops, that may flatter your ego, but does simply make your code unreadable. This is the same for OOP. I have been using OOP pattern in large software projects, but following the principles required often more work and planning.

In many cases, a project started with some procedural code only. But if you have hundreds of procedures and functions, things get easily unmaintainable. OOP was a way to organize my code and build conceptual units, that could be easily insulated from the rest of your code. Using classes often helped to ensure, that the code had no unwanted dependencies. And some of my classes could be used in other projects too, which saved me some work.

Javascript has - in any aspect - some limitations. The class concept is only "sort of", so you will not have full encapsulation and no fine grained control over visibility. Even if you follow OOP patterns, the result will not as good as you may expect. I suppose, this is similar with FP-code. It is only "sort of", not the same like using Haskell or Erlang.

Anyway, OOP is not "en vogue" in web programming, but my own experiments where quite successfull. See the DML-project for more information. I will not tell anybody that this is the way they shoud build their applications, but for me, but I´m quite happy with the performance. But I´m more a web programmer rather than an web designer...

Collapse
 
fritzlolpro profile image
Fedor

Thats right!
And considerring the pros and cons of each paradigm and language everything comes to the communication.
Every team should carefully finegrain their approach and discuss how and what paradigms they will use to achive business goals. Thats the hardest part!

And holywars about paradigms should be left to the beer parties, best time were you can discuss such topics while having fun and learning something new :-)

Collapse
 
jonmodell profile image
Jonathan Modell

Using any pattern just for the sake of it IS counterproductive. Understanding inheritance, interfaces vs classes (or types) is extremely helpful for frontend developers, especially when building extensible, reusable components. That's an OOP concept. To create scalable frontends, one has to figure out a way to abstract away what is reusable.

On the other hand, React led developers through creating "class" components into creating "functional" components. Hopefully, devs learned the difference between a pure function and side effects. That's FP.

I don't see a real case in my daily life as a front-end programmer where i exclusively use one pattern or another. Choosing one for the sake of purity is definitely "counter productive", as you say. Understanding the scalability and testability of both approaches is key to creating a maintainable codebase.

Collapse
 
fritzlolpro profile image
Fedor

I can't agree more!
In my practice I often meet programmers who tend to search for an ultimate solution.
"We will use DI everywhere it will fix all problems"
"This new architecture aproach is supreme! And all others are outdated and useless"
etc.

Unfortunatly there are no silver bullets and universal solutions. You can't just blindly follow some paradigm (pattarns everywhere, FP etc.). Thats the hardest part of our job. Thinking :-)

In my daily life as a programmer I use paterns from time to time. e.g. bebel\swc plugins use visitor pattern, or we proxy some events on our page of the target is not downloaded and than we push them out of stack.

In my opinion a frontend developer should be familiar with patterns and other aproaches. He maybe wouldnt use them in clear form in day to day work, but his code will be better.

Collapse
 
ranjancse profile image
Ranjan Dailata • Edited

Great blog post.

Sorry, just a misleading title. I thought you are conveying things in a highly generic manner, However, this post predominately targets toward the "Frontend Development".

Collapse
 
fritzlolpro profile image
Fedor

Thank you so much for your feedback!
You are completely right so I made changes to the title.

Collapse
 
ranjancse profile image
Ranjan Dailata

You are welcome!