31Jan

Patterns are the part of programming that needs to be studied regardless of the specific language, so that doesn’t matter what exactly you use: C, C++, C# or JavaScript, each of them uses some of the programming patterns, but there is the most interesting point how to implement the concept according to language specifics.

Subscribe to our channels!
Youtube
Facebook
Twitter
LinkedIn
Instagram
Google +

Here you can read all the information in written form:

Hello, everybody, and welcome to our blog. With this article we open the series of tutorials about programming patterns in JavaScript. So today we’re going to answer the basic question about this topic: why do we need programming patterns? 

About specifics of this tutorial

If you’re familiar at least with basics of JavaScript, then you should know, that this programming language has many differences with others. The most sensitive aspect for us is an object model: it has nothing to do with OOP originally (of course now we have class from ES6, but originally you should’ve done many things to make work at least basic aspects), that’s why in this tutorial series we’ll learn how to interpret the most common patterns and principles to JS with all the specifics.

Ultimate Question

That can be not so obvious thing to answer, why do we need patterns at all, but I can give you multiple reasons why you have to use programming patterns. With programming patterns you can:

  1. Prevent reinvention of wheel;
  2. Increase speed of code writing;
  3. Make code readable for everybody;

Let’s go one by one and investigate each reason thoroughly.

Reinvention of wheel

The thing that want to avoid here is re-invention of patterns. So normally patterns resolve some typical tasks (e.g. single instance class, run-time type initialization etc.) and then you know how to implement this specific thing there’s no need to create it from scratch. And as you can understand then you don’t know how to implement patterns for typical tasks you’ll start from zero, and there’s no guarantee that it’ll be done efficient enough.

Speed of coding

This point is in a really close connection with previous one. Let’s say you know how to resolve typical tasks with patterns it means that time of writing for such code will be decreased. E.g. for example you found out that switching between algorithms in run-time is required and then you know Strategy pattern, you can just take and use it in place, and you can tell for sure, that this solution is an approved and tested one. So stability is onboard as well.

Readability of code

Normally on projects of any difficulty level other developers need to read code of each other. And then you see something that was fully invented by different person and lives its own live it can be a tricky thing to understand what’s actually going on here. It will be closer to translation from foreign language to your own. While the usage of patterns that both developers are familiar with can be kind of an international language, so you see common pattern and you already know, what problem is solved here and how it works (abstractions and structure inside, e.g. Factory pattern normally requires types that can be produced in the future).

Ultimate answer (to Life, The Universe and Everything)

You need patterns mainly to use approaches that were created, approved and tested by other developers for you. Also then you used typical way to resolve some development problem it must’ve been understood by other developers correctly, what will save time in future for everybody.

Summary

Today we went through the basic reasons for patterns usage, I hope they’re clear enough and know you want to include programming patterns to your ‘necessary-to-study’ list. Next time we will start with exact patterns and you can see them in practice, all the code of patterns will be available on the Github for your usage and questions.

We are looking forward to meeting you on our website soshace.com

Leave a Reply