Separation Of Concerns — Essential JavaScript

Ariel Salem
2 min readMar 1, 2017

--

AKA You Down with SoC?
This post will be an introduction into the importance of Separation of Concerns(SoC), and how it relates to every aspect of your program. Future posts will exemplify this in order to maximize categorical and collective understanding of the concept.

Separation of Concerns — What Does it Mean?
In a broad sense, SoC refers to the idea that computer programs should be separated into distinct sections so that each section addresses a specific concern. By distinguishing parts of our code within well-defined interfaces, we can create programs that have distinct subroutines mapped out into more readable terms. In doing so, we can maintain order within our program while allowing for more concise logical conclusions on a step-by-step basis. Furthermore, these subroutines may be utilized by other programs as a means function callbacks.

This may seem like a pretty basic concept, but if you’re not actively trying to compartmentalize parts of your program it can be very easy to simply write spaghetti code. The important thing to realize is that SoC, just like anything, can become routine with just a little bit of practice. For example, when putting dishes away, it’s intuitive not to pile everything together in one cupboard every single time. That would make sifting for bowls, plates, and utensils a nightmare! That’s where SoC comes in. We separate the kitchenware based on similarities so that we can maintain order and accessibility without having to rummage through chaos anytime we get hungry. In much the same way separating parts of our code gives us the opportunity to easily access, adjust, and reuse our code while maintaining readability.

Where Do I Begin?
Knowing where to start, especially when you’re first starting off, can be tough. For me, it always helps to remember that we should keep our code D-R-Y(Don’t Repeat Yourself) instead of W-E-T(Writing Everything Twice). That is to say, if you find yourself in a situation where you’re writing the same (or similar) line of code over and over and over again, you may be better of creating a function outside your existing program that you can invoke whenever you need it. This may not seem like much if you’re just multiplying numbers, but remember these little steps add up to become massive time-savers. By starting off with the basics, you are reshaping the way you think about your program. In doing so, it will be easier to understand more elaborate SoC concepts that you may encounter in Classes, MVC, Node, etc…

Quick Recap:
SoC is valuable in simplifying the development and maintenance of computer programs. When code is well-separated, individual sections can be reused, modified, and debugged with ease and independence. Implementing SoC won’t happen overnight, but it is important to always go over your code to try and find ways of separating your concerns into compartments of readable code. For examples on how Classes are a form SoC, check out this post.

--

--

Ariel Salem

Full Stack Developer | Lover of Tech, Programming, and all things JavaScript