Design Patterns: How important is it to study them?

I think I understand javaScript pretty well. But I still have a long way to go.

Do you think learning about design patterns is a good use of time? Or is it an old forgotten concept of the past, I wonder because none of the resources I’ve learned JS from (Books, Udemy, YouTube, etc) have ever mentioned this concept.

If it is worth my time, where should I begin?

Design patterns in general are always worth learning. The book “Design Patterns” (aka the GoF book as in “gang of four”) is, however, primarily geared toward languages that use a Class/Object system, and even for those tends to be quite out of date when it comes to many patterns. Javascript has many of the book’s design patterns built in (for example, Iterator). I really can’t recommend the GoF book in this day and age.

If you want to learn design patterns with a specific javascript bent, you could always check out the free book Javascript Design Patterns

3 Likes

They are good to know if another programmer mentions one in a code review or something. But I think a better way to learn commonly used patterns is to write code in an environment where there are some senior programmers. The more variety of people you work with the more high level patterns you’ll see and be able to choose from. If you want to see how often the documented patterns are used in the wild, choose one a week and see where and if you can find it in the projects you are working on. Or if your code could be improved by using that pattern.

2 Likes

Thanks, that was helpful :smiley:

I really recommend reading the Addy Osmani JS Design Patterns book linked in the post above! I wouldn’t say it’s critical early on, but once you start working regularly with frameworks like React, Vue, etc. it’s useful to read to understand the underlying systems these frameworks are using to achieve their magic. It will make you better JS programmer, and it will make reading more advanced articles on things like virtual DOM easier. There are some secondary benefits of reading expert-level code and patterns in JS like seeing the steps and concepts they take to keep things clean (encapsulation, separation of concerns, decorators), which I find myself appreciating and trying to implement more often the more time I code even with my frameworks. It’s even possible in a job some day you will need to write your own internal framework instead of use external ones.

1 Like

I agree it’s a good book to read. However, I would warn that many of the design patterns copied directly from the original book are not needed in a language like JavaScript where we have first class functions. For example, the command pattern. And the Factory Pattern he describes is overkill. In JavaScript the factory pattern is simply a function that returns a JS object. It could definitely be a good book to study and see which of those patterns senior programmers are using. And then to try to learn why some of those patterns from the book are never used in the real world. So just read it with a grain of salt: many of those patterns were copied from the Object Oriented Java world, from the kind of outdated Gang of Four Design Patterns book.