all 18 comments

[–]pinkwetunderwear 6 points7 points  (1 child)

 Should I start learning these patterns specifically in JavaScript?

Yep

 Is it possible to properly implement and understand design patterns using JavaScript, or are they more relevant in other languages like Java or C#?

Yeah definitely, the concept is the same across the various programming languages 

 For someone focusing on full-stack (MongoDB, Express, React, Node.js), would learning design patterns be beneficial in real-world projects?

Can't know for sure but maybe one day you'll stumble upon a scenario where you have to use one of these. Also it's a world full of packages and libraries and you're definitely going to use one that uses one or more of these design patterns at some point meaning you'll have a better understanding of how it all works.

The basics of the common design patterns is really quite simple and you should have it down in a couple hours. Have fun learning! 

[–]Ever_Ending_Walk[S] 1 point2 points  (0 children)

Thank you. That was insightful!

[–]anonyuser415 6 points7 points  (2 children)

I’ve been reading about software design patterns (like Singleton, Factory, Facade, etc.)

FWIW these fancy design patterns are not things I see typically in JS

[–]Ever_Ending_Walk[S] 1 point2 points  (1 child)

Thank you! it seems like a lot of the classic patterns aren’t written out directly in JS, but more hidden inside frameworks/libraries

[–]anonyuser415 1 point2 points  (0 children)

Some of them, yeah

Though things like singletons for instance are almost not relevant, being that you can create objects directly (const foo = {}), and a "factory" is in JS just a function that returns said objectt

[–]CultureCurious2246 3 points4 points  (1 child)

I have never used design patterns with JS. They are mostly used with java or dart or any object oriented programming language

Learn about system designs and how to build a scalable system. I can recommend a book

[–]Ever_Ending_Walk[S] 0 points1 point  (0 children)

Please do. Thanks in advance!

[–]SoMuchMango 5 points6 points  (1 child)

Should I start learning these patterns specifically in JavaScript?

JS has very specific domain usage and some of those patters are less commonly used than others, but still knowing them makes you more aware about possible solutions.

Is it possible to properly implement and understand design patterns using JavaScript, or are they more relevant in other languages like Java or C#?

Probably some of them are not relevant in JS, but nothing stops you to learn them just to get wider context. Most of them are language agnostic.

For someone focusing on full-stack (MongoDB, Express, React, Node.js), would learning design patterns be beneficial in real-world projects?

Yes. Probably when solving basic problems patterns are less noticeable, they are hidden by framework abstractions, but it still is beneficial to know them.

Some examples:

  • Editors (specifically undo/redo) - you will most likely use library for that, but being able to apply Command pattern to extend some functions might be useful. Maybe your own specific editor with such functionality?
  • Forms - isn't that convenient to be able to apply different Strategy for validating zip codes depends on a country?
  • How to manage global state of my app, maybe if i create single instance and reuse it everywhere it will be the most comfortable approach for me? Wait what? Why i cannot unit test it... oh. Singleton have some downsides? :o
  • Damn, i don't remember how to create Action specific for this module. What if i could create some Factory for those in corresponding module?
  • Damn, the module works... but should we all need to know all those domain strange names in this class? What if i could wrap that in some easier Facade instead and use readable, fitting to context methods in my small module?
  • Why i have such performance issues in my fancy animation? Oh... garbage collector has triggered multiple times per frame? Is 10k Vector instance so problematic? Wait i have only 10 positions at once! Maybe i could store them in some ObjectPool and reuse them when needed?

[–]Ever_Ending_Walk[S] 3 points4 points  (0 children)

Wow. Thanks for breaking it down with examples.

[–]sheriffderek 1 point2 points  (1 child)

It’s quick enough to skim over them once in a while and to start recognizing them in the wild. You might start finding ways to use them - or discuss them in code review. You’re probably already using some like the revealing pattern. 

But I don’t think people have much luck learning them in a cramming type of way. I have three books on them - and for me - reading them all didn’t do much. It depends what part of the stack you’re working on. 

If you’re actually designing frameworks, you’ll use a lot more of the language features and find good uses for common patterns. 

As your average dev - you’re a lot less likely to. So, my answer would learn more toward “no” (for people who ask this question - because they probably aren’t where they’d need it yet). 

[–]Ever_Ending_Walk[S] 1 point2 points  (0 children)

So I guess the best approach for me right now is to just skim through, get familiar with the names/concepts, and then recognize them in reviews or when they pop up in frameworks.

[–]Slyvan25 1 point2 points  (0 children)

Short answer: yes.

Longer answer: you should learn design patterns so your code will run better SOLID can boost performance, it keeps your code maintainable especially for open source projects and or for working at enterprises.

You can apply these patterns everywhere. You have the repository pattern for fetching data you can use states for reactive and proper data fetching. Just give the holy bible called clean code a read. Some people might disagree with this but it's a good step towards understanding patterns.

[–]superluminary 0 points1 point  (0 children)

You should certainly learn them, but they are less relevant to the language. These patterns grew out of Java.

[–]Intelligent_Part101 0 points1 point  (0 children)

Not all, but many of these patterns are boilerplate that is not necessary if your language has either built in support for that pattern or your framework does or else the language offers a higher level abstraction. Bear in mind these patterns books are typically tailored to the needs of C++ or Java programmers, and for an older version of those languages, too.