<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Roman Verner</title>
    <description>The latest articles on DEV Community by Roman Verner (@romverner).</description>
    <link>https://dev.to/romverner</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F385453%2F179c9bd2-8f61-4f23-a3dc-fcc5f2037e2e.jpeg</url>
      <title>DEV Community: Roman Verner</title>
      <link>https://dev.to/romverner</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/romverner"/>
    <language>en</language>
    <item>
      <title>Web Developers, do you recommend building your own portfolio, or paying for an existing service?</title>
      <dc:creator>Roman Verner</dc:creator>
      <pubDate>Wed, 21 Apr 2021 13:23:20 +0000</pubDate>
      <link>https://dev.to/romverner/web-developers-do-you-recommend-building-your-own-portfolio-or-paying-for-an-existing-service-5369</link>
      <guid>https://dev.to/romverner/web-developers-do-you-recommend-building-your-own-portfolio-or-paying-for-an-existing-service-5369</guid>
      <description>&lt;p&gt;I know that building your own custom-coded website is a great opportunity to showcase your skills, but it's also something you need to maintain moving forward. Is it worth the hassle of maintaining a custom-coded website as opposed to going with a 3rd party provider (such as SquareSpace or Wordpress)?&lt;/p&gt;

&lt;p&gt;I'm considering moving to a 3rd party provider as I find maintaining my own website to be more of a distraction from other, more important, work. Before I make the switch I thought I'd see what you wise folks had to say. Thanks!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>healthydebate</category>
    </item>
    <item>
      <title>User Behavior Tracking w/ JavaScript (P2)</title>
      <dc:creator>Roman Verner</dc:creator>
      <pubDate>Fri, 05 Mar 2021 18:13:56 +0000</pubDate>
      <link>https://dev.to/romverner/user-behavior-analysis-w-javascript-p2-2834</link>
      <guid>https://dev.to/romverner/user-behavior-analysis-w-javascript-p2-2834</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/91NclqtDt6c"&gt;
&lt;/iframe&gt;
&lt;br&gt;
Hello DEV community! It's been a while since my first post on this project. &lt;a href="https://dev.to/romverner/making-a-user-behavior-tracking-app-w-javascript-p1-37fi"&gt;Here&lt;/a&gt; is a link in case you missed part one, but if you haven't read the original post, no worries. We're going to rewrite and refactor the original code to better suit our needs moving forward. I took a hiatus from my personal projects after starting a new job, but this project in particular has me excited to start back up again.&lt;/p&gt;
&lt;h2&gt;
  
  
  Quick Recap:
&lt;/h2&gt;

&lt;p&gt;We're trying to create a front-end JS module that will allow us to track user behavior as it relates to interacting with our online forms. The intent being that we can proactively discover and correct confusing areas in said forms, and improve the overall experience for the end user; however, this isn't the only application of our app. Once we setup a robust tracking system, we can even detect more abstract behaviors, such as an online shopper hovering over the "Purchase" button and hesitating before officially submitting their order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Refactoring:&lt;/strong&gt;&lt;br&gt;
It's been a while since the last post so I decided to restart the project and introduce some slightly different and refactored logic. All of this is covered in the embedded video as well as the code snippets below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tracking By Element:&lt;/strong&gt;&lt;br&gt;
The first thing we need to acknowledge is that each HTML element that we want to track has different types of interactivity. For example, users typically can't focus on span elements, since span elements don't contain a way for users to input values. The five main events we'll record are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event" rel="noopener noreferrer"&gt;click&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event" rel="noopener noreferrer"&gt;auxclick&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/focus_event" rel="noopener noreferrer"&gt;focus&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/blur_event" rel="noopener noreferrer"&gt;blur&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseover_event" rel="noopener noreferrer"&gt;mouseover&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseleave_event" rel="noopener noreferrer"&gt;mouseleave&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To track interactions with button elements we might use mouseover, mouseleave, and click. To track input elements, we might use focus, blur, mouseover, and mouseleave.&lt;/p&gt;

&lt;p&gt;Since different elements will use different events to record behavior, we need to create tracking functions specifically tailored to each element. If we discover that we're coding too repetitively, we can refactor down the line. So, let's start with our tracking functions.&lt;/p&gt;

&lt;p&gt;Just as we did in the previous post, these functions are going to be contained within an &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE" rel="noopener noreferrer"&gt;IIFE&lt;/a&gt;. Let's outline some of our most important functions.&lt;/p&gt;
&lt;h1&gt;
  
  
  Code Overview
&lt;/h1&gt;

&lt;p&gt;For the full context behind the functions listed below, please visit the &lt;a href="https://github.com/romverner/HAWK" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;HAWK.track(elementId)&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
This function will take in an element's ID and automatically setup the necessary event listeners for that element type. We can get the element type using the &lt;code&gt;nodeName&lt;/code&gt; property, which returns string values such as &lt;code&gt;'SPAN'&lt;/code&gt;, &lt;code&gt;'DIV'&lt;/code&gt;, etc.. This is one of the first changes as compared to the first post in this series. We are now using the &lt;code&gt;nodeName&lt;/code&gt; property. This will allow us to create a controller function called &lt;code&gt;_addListeners&lt;/code&gt; that's effectively one big switch statement referencing the specific element type listener functions.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const _track = (id) =&amp;gt; {
    let elementRef = _d.getElementById(id);
    let elementType = elementRef.nodeName;
    if (_checkConditions(id, elementType)) {
        _data.trackers[id] = _createTrackObj(id, elementType, elementRef);
        _addListeners(id, elementType, elementRef);
    };
};


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;_addListeners(elementId, elementReference, nodeName)&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
This function takes in the element ID, the element's HTML reference (aka the product of &lt;code&gt;document.getElementById()&lt;/code&gt;), and the nodeName. Technically we don't need the second and third parameters as we could just reacquire them within the scope of the function, but we already gather that info from the track() function, so it's easier to just pass it down.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const _addListeners = (id, type, reference) =&amp;gt; {
    switch (type) {
        case _elTypes.button:
            reference.addEventListener(_eventTypes.c, () =&amp;gt; {
                _clickListen(id);
            });
            Object.keys(_eventTypes.m).forEach((key, i) =&amp;gt; {
                reference.addEventListener(_eventTypes.m[key], () =&amp;gt; {
                    _mouseListen(id, i);
                });
            });
            break;

        case _elTypes.span:
            Object.keys(_eventTypes.m).forEach((key, i) =&amp;gt; {
                reference.addEventListener(_eventTypes.m[key], () =&amp;gt; {
                    _mouseListen(id, i);
                });
            });
            break;

        case _elTypes.input:
            Object.keys(_eventTypes.m).forEach((key, i) =&amp;gt; {
                reference.addEventListener(_eventTypes.m[key], () =&amp;gt; {
                    _mouseListen(id, i);
                });
            });
            Object.keys(_eventTypes.fb).forEach((key, i) =&amp;gt; {
                reference.addEventListener(_eventTypes.fb[key], () =&amp;gt; {
                    _focusListen(id, i);
               });
            });
            break;

        default:
            break;
    };
};


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;_focusListen, _mouseListen, _clickListen&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
These functions store the action to be performed on each event. Since every element may require different types of event listeners, we code most of our repetitive code here. This is one of the few areas that I want to re-factor down the line, but I'd rather focus on getting to a minimum viable product first.&lt;/p&gt;
&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/romverner" rel="noopener noreferrer"&gt;
        romverner
      &lt;/a&gt; / &lt;a href="https://github.com/romverner/HAWK" rel="noopener noreferrer"&gt;
        HAWK
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;HAWK&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;This repository is setup to run/test right out of the gate. Simply pull the repo, open up the index.html file in your preferred browser, and open up your developer console to interact with the HAWK module. HAWK.results() will console log all tracked events.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Tracking Elements&lt;/h3&gt;

&lt;/div&gt;
&lt;p&gt;The HAWK.track function takes in an element ID as its parameter. It will automatically attach any listeners based on what type of element it is. As of the time of this writing, the only tracked elements are SPAN's, INPUT's, and BUTTON's.&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/romverner/HAWK" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;Thank you for taking the time to read my post!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript Module Pattern (Part 2): Default Module Functionality &amp; Object De-structuring</title>
      <dc:creator>Roman Verner</dc:creator>
      <pubDate>Tue, 04 Aug 2020 22:30:18 +0000</pubDate>
      <link>https://dev.to/romverner/javascript-module-pattern-part-2-default-module-functionality-object-de-structuring-hjf</link>
      <guid>https://dev.to/romverner/javascript-module-pattern-part-2-default-module-functionality-object-de-structuring-hjf</guid>
      <description>&lt;p&gt;I mentioned in a &lt;a href="https://dev.to/romverner/the-javascript-module-pattern-what-is-it-why-is-it-useful-18g5"&gt;previous post&lt;/a&gt; that I've been trying to implement the module pattern to our front-end javascript code at work. And I'm happy to report that so far it's going well. I've made a few discoveries that I thought I'd share!&lt;/p&gt;

&lt;h2&gt;
  
  
  Default Module Functionality
&lt;/h2&gt;

&lt;p&gt;When I first started learning about the module pattern -- and IIFE's in general -- I never considered the idea of adding default functionality to the newly created modules. In hindsight, now I realize that actually would have been quite useful! If you have a web app that contains many smaller apps within it, it can be tough to bring on new developers if you're not using a framework. Why? Because each app may be coded in an entirely different style -- one issue among many. Remember, one of the main reasons for introducing the module pattern is to begin to standardize.&lt;/p&gt;

&lt;p&gt;Anyway, let's get to the code. Let's imagine we have a standard &lt;code&gt;MAIN&lt;/code&gt; module from which all other modules will be created. Here, it's written in two different ways to show what's possible:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As you can see, in the first IIFE -- &lt;code&gt;MAIN&lt;/code&gt; -- we store our modules in an object and then just point to it in the return object of the &lt;code&gt;MAIN&lt;/code&gt; IIFE. In the second IIFE  -- &lt;code&gt;MAIN2&lt;/code&gt; --, we actually create a reference to another IIFE in our return object. I prefer the object references of the first method for the sake of simplicity, but the second method allows anonymously scoped functionality to be added to all of our new modules!&lt;/p&gt;

&lt;p&gt;Let's now take a look:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As you can see, both methods offer ways to provide default functionality; however, the second method allows us to take that default functionality to a whole new level. By modifying our &lt;code&gt;_createModule&lt;/code&gt; function in &lt;code&gt;MAIN2&lt;/code&gt; and adding a second parameter for a file path, we are now opening up the possibility to &lt;strong&gt;load&lt;/strong&gt; module settings as soon as the &lt;code&gt;createModule&lt;/code&gt; function is run! No interaction outside of supplying the two parameters to &lt;code&gt;_createModule&lt;/code&gt; required! While I still prefer the simplicity of the first method, the second method now allows us to further begin introducing a whole new set of coding standards that will unify our apps from a developers prospective. On top of this, the anonymous scoping and immediately invoked nature of IIFE's has also allowed us to start developing our very own little framework!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F141h2q3o8sw0vcf0gu2f.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F141h2q3o8sw0vcf0gu2f.gif" alt="let me pat myself on the back" width="400" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, bear with me, I only made these discoveries today, so I won't go into any further details until I've had some time to mess around with these concepts. In the meantime, here is one final applied example using a pretend app for Wahoo to help visualize how this organizes your code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;What are your thoughts? I &lt;em&gt;may&lt;/em&gt; be biased, but I think that looks neat and tidy!&lt;/p&gt;

&lt;h2&gt;
  
  
  Object Destructuring Saves Time
&lt;/h2&gt;

&lt;p&gt;Having the ability to add default settings to your modules aside, here's another small tidbit I'd like to share. Remember to de-structure your nested objects for easier access! Given that everything in your modules is in an object, you can just pick and pull what you need.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Anyway, that's all I have to share for now. Hope you found this useful!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>todayilearned</category>
      <category>todayisearched</category>
    </item>
    <item>
      <title>Making a User Behavior Tracking App w/ Javascript (P1)</title>
      <dc:creator>Roman Verner</dc:creator>
      <pubDate>Thu, 25 Jun 2020 15:44:44 +0000</pubDate>
      <link>https://dev.to/romverner/making-a-user-behavior-tracking-app-w-javascript-p1-37fi</link>
      <guid>https://dev.to/romverner/making-a-user-behavior-tracking-app-w-javascript-p1-37fi</guid>
      <description>&lt;p&gt;Welcome! This post has an &lt;a href="https://youtu.be/UJjAzdewCSQ" rel="noopener noreferrer"&gt;associated video&lt;/a&gt; if you're more inclined to follow along with the actual coding process. Let's outline some general information about the project so you can see if it's something your interested in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt;&lt;br&gt;
To create an application/script that tracks a user's behavior while interacting with an online form.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt;&lt;br&gt;
To detect if any parts of a form take longer to fill out or multiple tries in an effort to determine if there are areas in our forms that could be made clearer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applications:&lt;/strong&gt;&lt;br&gt;
My company works tangentially alongside the healthcare field. Many of our applications have multi-page intake forms that request data/information about clients. With healthcare being as complex as it is, often times there can be miscommunications or unclear directions about which forms need which information. If we could detect where our users are having trouble filling out our forms, we would then be empowered to go in and update the form to make it easier on our users!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code:&lt;/strong&gt;&lt;br&gt;
In this first post (and video), we start off with some very simple event listeners. The four events we listen for are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/focus_event" rel="noopener noreferrer"&gt;focus&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/blur_event" rel="noopener noreferrer"&gt;blur&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseover_event" rel="noopener noreferrer"&gt;mouseover&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseleave_event" rel="noopener noreferrer"&gt;mouseleave&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When these events fire, we simply record the relative time at which the event occurred so we can later cross compare between related events. In our case, we are using the &lt;code&gt;performance&lt;/code&gt; interface, which stores functionality typically used to acquire performance related information about a user's session. Contained within this interface is the &lt;code&gt;now()&lt;/code&gt; function that returns the milliseconds that have gone by since the start of the session. Given that we only care about the length of time a user spends interacting with input elements, this works well for our purposes. It is important to note, the &lt;code&gt;performance.now()&lt;/code&gt; function &lt;em&gt;rounds&lt;/em&gt; the value to the nearest millisecond, but that is more than accurate enough for our use case.&lt;/p&gt;

&lt;p&gt;Here is what our starter code looks like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const HAWK = (() =&amp;gt; {
    let _data = {};

    const _trackTextInput = (elementId) =&amp;gt; {
        const _d = document;

        _data[elementId] = {};
        _data[elementId].focusBlur = [[],[]]; // index0 arr = focus
        _data[elementId].mouseOver = [[],[]];

        _d.getElementById(elementId).addEventListener('focus', 
        () =&amp;gt; {
                _data[elementId].focusBlur[0].push(performance.now());
        });

        _d.getElementById(elementId).addEventListener('blur', 
        () =&amp;gt; {
            _data[elementId].focusBlur[1].push(performance.now());
        });

        _d.getElementById(elementId).addEventListener('mouseover', 
        () =&amp;gt; {
            _data[elementId].mouseOver[0].push(performance.now());
        });

        _d.getElementById(elementId).addEventListener('mouseleave', 
        () =&amp;gt; {
            _data[elementId].mouseOver[1].push(performance.now());
        });
    };

    const _results = () =&amp;gt; {
        console.log(_data);
    };

    // =================================================================
    return {
        trackTextInput(elementId) {
            _trackTextInput(elementId);
        },
        results() {
            _results()
        }
    };
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The name 'HAWK' doesn't stand for anything. I just thought it sounded like a fun name to go with for this project. I realize now that it probably sounds a little menacing, but that's not the intent! Haha.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Helpful Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you're unfamiliar with immediately invoked function expressions (IIFE's), I found &lt;a href="https://flaviocopes.com/javascript-iife/" rel="noopener noreferrer"&gt;this post&lt;/a&gt; to be incredibly helpful.&lt;/li&gt;
&lt;li&gt;If you'd like to read up on the &lt;code&gt;performance&lt;/code&gt; interface and all that it has to offer, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance" rel="noopener noreferrer"&gt;MDN&lt;/a&gt; is always a great go to.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The JavaScript Module Pattern: What is it? Why is it useful?</title>
      <dc:creator>Roman Verner</dc:creator>
      <pubDate>Thu, 28 May 2020 02:53:24 +0000</pubDate>
      <link>https://dev.to/romverner/the-javascript-module-pattern-what-is-it-why-is-it-useful-18g5</link>
      <guid>https://dev.to/romverner/the-javascript-module-pattern-what-is-it-why-is-it-useful-18g5</guid>
      <description>&lt;p&gt;From my experience, learning JavaScript has been like opening Pandora's box. There are so many topics to study, so many niche functions, that I often lose myself out of curiosity. Sometimes it feels like my time is well spent, and other times it feels like I'm giving in to an inner desire to procrastinate with distractions. Harder still, is finding ways to implement any new knowledge into everyday practice. So I gave it a shot with the module pattern!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ur2sd1qsi9krq9km9cl.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ur2sd1qsi9krq9km9cl.gif" alt="pandoras box" width="350" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I work in several different code bases at my job. One of our largest code bases is a behemoth of a project file, and parsing through some of the front-end can be a little tough at times. Not because any singular person wrote bad code, but because the project was started at a time of change for the department, and certain standards weren't put in place. Standards involving more subtle things like the use of global variables. In an effort to provide a solution for these issues, I decided to research how other companies structure their front ends to keep the code base easier to maintain. First, let's start by listing out the issues we're trying to solve:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Over-reliance on global variables.&lt;/li&gt;
&lt;li&gt;Redundant and cumbersome naming conventions for declared functions/variables.&lt;/li&gt;
&lt;li&gt;No consistency in styling across the project's javascript files.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While I came across several unique and interesting solutions, the one that stuck the most with me, was the &lt;a href="https://addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript" rel="noopener noreferrer"&gt;&lt;strong&gt;module pattern&lt;/strong&gt;&lt;/a&gt;. I loved it's simplicity in design, and it seemed like the perfect solution for the code-base I was working with at the time.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Basics
&lt;/h1&gt;

&lt;p&gt;The module pattern is just an organizational structure for your code. The basic premise is that you have one or more global objects that house your application's modules. What does that actually look like? Let's put down some code. &lt;/p&gt;

&lt;p&gt;In the spirit of remaining on brand, let's &lt;em&gt;pretend&lt;/em&gt; we're making an &lt;a href="https://animal-crossing.com/" rel="noopener noreferrer"&gt;Animal Crossing&lt;/a&gt; themed application called 'Nookbook'. First, we create a new global variable/reference called &lt;code&gt;Nookbook&lt;/code&gt; and set it to an Immediately-invoked Function Expression (IIFE). This post won't necessarily focus on how IIFEs work, but if you'd like to read up on them, you can do so on &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Nookbook = (() =&amp;gt; {
    const _modules = {};
    const _createModule = (_moduleName) =&amp;gt; {
        ((N) =&amp;gt; {
            _modules.moduleName = {};
            N[moduleName] = { get N() {return _modules.moduleName; } };
        })(Nookbook);
    };

    return {
        createModule(moduleName) {
            _createModule(moduleName);
        }
    };
})(); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The module pattern works by storing everything in a series of contextual hierarchies that take form through the use of objects. Our Nookbook app could have several modules that one might imagine an Animal Crossing app to have. Such as a 'Marketplace' module, or perhaps a 'Profile' module that contains functionality surrounding user profiles. In those cases, we could create what we refer to as a &lt;em&gt;namespace&lt;/em&gt; for those modules by using our &lt;code&gt;createModule&lt;/code&gt; function. Notice that it simply calls the &lt;code&gt;_createModule&lt;/code&gt; function declared within our IIFE's scope. The typical naming convention for variables declared within an IIFE is to prefix them with underscores in order to differentiate what's scoped to the IIFE and what's not. This is important, since IIFE's are anonymously scoped, their inner properties cannot be accessed unless we interact with them through the return object's methods. To create a module:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Nookbook.createModule('Marketplace');

// This is what our IIFE looks like after running the above fn.
const Nookbook = (() =&amp;gt; {
    const _modules = { 
        Marketplace: {} 
    };
    const _createModule = (_moduleName) =&amp;gt; {
        ...
    };

    return {
        createModule(moduleName) {
            _createModule(moduleName);
        },
        get Marketplace() {
            return _modules.Marketplace;
        }
    };
})(); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Notice we created an object called &lt;code&gt;Marketplace&lt;/code&gt; that we're storing in our &lt;code&gt;_modules&lt;/code&gt; object. It also adds a method to the return object of &lt;code&gt;Nookbook&lt;/code&gt;. The method uses the &lt;code&gt;get&lt;/code&gt; syntax to allow us to access the newly created object directly. This line is what creates that getter:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;N[moduleName] = { get N() { return _modules.moduleName; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here, &lt;code&gt;N&lt;/code&gt; is just the alias we gave our Nookbook IIFE. All we are doing is creating a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get" rel="noopener noreferrer"&gt;getter&lt;/a&gt; for our marketplace object -- the function simply returns the module's object. Now if we want to add functionality to our marketplace, we can simply declare functions in the standard way:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Nookbook.Marketplace.addItem = (itemName, askingPrice) =&amp;gt; {
    // ... code here
};

// To call the function:
Nookbook.Marketplace.addItem('Ironwood Kitchenette', 150000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It's as simple as that!&lt;/p&gt;

&lt;h1&gt;
  
  
  Benefits
&lt;/h1&gt;

&lt;p&gt;So what exactly are the benefits of structuring your applications around this design pattern? Introducing any design structure, by default introduces standards that will make your code more uniform. In this case, the paths of your functions now contain contextual information. Not only is our code more uniform, it also categorizes and houses information in a more meaningful way:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Standard function declaration.
function addUserProfile() { ... };
function updateProfileInformation() { ... };

// Object notation is easier to read and provides context.
Nookbook.Profile.add = () =&amp;gt; { ... };
Nookbook.Profile.update = () =&amp;gt; { ... };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Often times, knowing a function is contained within the &lt;code&gt;Profile&lt;/code&gt; module is enough context to understand the functions intent. This means we can start to simplify naming conventions and actually make code more intuitive to read.&lt;/p&gt;

&lt;p&gt;Let's keep diving further. Say we want to separate out module-specific constants for things that don't change often -- like file paths. Instead of relying on global variables, we can simply create an object to hold our constants for each module.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// We begin by creating an empty object to hold our constants.
Nookbook.Profile.CONST = {};

// Then we can organize our constants however we like.
Nookbook.Profile.CONST.PATHS = {
    MAIN: '../Profile/main.html',
    FRIENDS: '../Profile/friends.html'
};

// Here's an alternative way of declaring what we wrote above in a more concise way.
Nookbook.Profile.CONST = {
    PATHS: {
        MAIN: '../Profile/main.html',
        FRIENDS: '../Profile/friends.html'
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This creates an easy to remember location for all of our constant variables. If you design your own naming standards, then you begin to develop more consistency in the long term! In my case, I set the standard that every module has a &lt;code&gt;CONST&lt;/code&gt; object holding all of it's constants. Now, no matter which module I'm working in, I always know where all of my constants are declared. Next, let's create some functions that behave in a 'global' manner.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Nookbook = (() =&amp;gt; {
    const _modules = {};
    const _createModule = (_moduleName) =&amp;gt; {
        ...
    };

    const _loadPage = (_pageName) =&amp;gt; {
        // code that makes a server call for desired file
    };

    return {
        createModule(moduleName) {
            _createModule(moduleName);
        },
        loadPage(pageName) {
            _loadPage(pageName);
        }
    };
})(); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above example we added a function called &lt;code&gt;loadPage&lt;/code&gt; that we're pretending has code that makes a server call for an HTML file. By creating this function in the main &lt;code&gt;Nookbook&lt;/code&gt; IIFE, we can think of it as a global function, because it's not contained within any one specific module, and every module has access to it:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Nookbook.Profile.loadFriends = () =&amp;gt; {
    Nookbook.loadPage(Nookbook.Profile.CONST.PATHS.FRIENDS);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We now begin to see how nicely all of this begins to fit together. We call on our new loadPage() function in our module, and we call on our object holding our constants for the page's file path. Everything is incredibly easy to read through, if perhaps verging on being a little verbose.&lt;/p&gt;

&lt;h1&gt;
  
  
  Drawbacks
&lt;/h1&gt;

&lt;p&gt;Personally, I haven't encountered all too many drawbacks to the module pattern except that it can be complicated to integrate into an existing code-bases. It can also get a little verbose for applications that are incredibly large. If you have modules with several sub-modules, the contextual paths may get a little tedious to work with:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Nookbook.Profile.Wishlist.add = (itemName) =&amp;gt; { ... };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Having to type &lt;code&gt;Nookbook.Profile.Wishlist&lt;/code&gt; for each function I want to declare for the wishlist sub-module is a little annoying. Fortunately, you could just create local references, such as:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const NPW = Nookbook.Profile.Wishlist;
NPW.add = () =&amp;gt; { ... };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The only problem with a reference like this, is that they become global, and thus began to slowly defeat the original purpose of using the module pattern -- at least in my case. I have found that you can often just design the code in a way that relies on more modules and less sub-modules, but it's still a limiting factor. However, since the original goal was to simply &lt;em&gt;lower&lt;/em&gt; global variable usage, having these references isn't a big deal. The problem lies with the fact that if your app is being worked on by multiple developers, you need to develop standards for where these global references are declared as early as possible. You wouldn't want developers accidentally declaring references with the same name, but to different modules. Here are two imaginary modules with sub-modules where this could be an issue:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const NPS = Nookbook.Profile.Settings;
const NPS = Nookbook.Pattern.Storage;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you don't have standards in place to account for this, you could potentially start to run into issues!&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusions
&lt;/h1&gt;

&lt;p&gt;I'm still seeing how far I can take this design structure, so I'll keep posting more as I find cool/unique ways to implement and use the module pattern. For now, all I can say, is that it's already beginning to help organize our code and cut down on headaches with overlapping functionality and redundant function names.&lt;/p&gt;

&lt;p&gt;If you have any questions, please feel free to ask. If you spotted anything wrong in this post, please let me know so that I may correct it! Also, as I am still learning, I would greatly appreciate hearing your experience and discoveries working with the module pattern!&lt;/p&gt;

&lt;p&gt;Update: If you'd like to read more, &lt;a href="https://dev.to/romverner/javascript-module-pattern-part-2-default-module-functionality-object-de-structuring-hjf"&gt;here&lt;/a&gt; is the second post in this series!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Piecing Together Bootcamp Knowledge</title>
      <dc:creator>Roman Verner</dc:creator>
      <pubDate>Thu, 14 May 2020 19:12:24 +0000</pubDate>
      <link>https://dev.to/romverner/piecing-together-bootcamp-knowledge-g5p</link>
      <guid>https://dev.to/romverner/piecing-together-bootcamp-knowledge-g5p</guid>
      <description>&lt;p&gt;Perhaps this isn't a unique experience, and everyone faces the same conundrum during their coding careers, but I found the process of graduating a coding bootcamp &lt;em&gt;very&lt;/em&gt; jarring. You're thrown into the world having learned, at some foundational level, several new technologies. It's up to you to figure out how to leverage those technologies to create applications that you can grow your portfolio with. How are you supposed to take that newfound knowledge and piece it all together?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/mNdOc0Aziv88E/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/mNdOc0Aziv88E/giphy.gif" alt="Schitt's Creek Overwhelmed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thinking about this would often times make my head spin. I had several ideas for projects, but wasn't sure how feasible they were with my skill-set. After many failed projects, I realized I had to start small and simply re-learn -- this time in greater detail -- the same concepts we learned in bootcamp. In this series of posts, I document that process, and some things I've discovered along the way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/PkKjXRfMCxnRMHQWqE/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/PkKjXRfMCxnRMHQWqE/giphy.gif" alt="Timmy Tommy R Cute"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To keep myself motivated, I have chosen a themed app to match my current obsession: &lt;strong&gt;Animal Crossing&lt;/strong&gt;. The goal is simple, create a 'dashboard' that will allow me to view my friend's turnip prices and item wish-lists. The application should use MySQL, Node/Express, and React. If you're interested, follow along! In the next post I'll go over creating a basic boilerplate for the application. &lt;/p&gt;

&lt;p&gt;How has your experience been graduating bootcamp?&lt;/p&gt;

</description>
      <category>bootcamp</category>
      <category>learning</category>
      <category>mysql</category>
      <category>react</category>
    </item>
  </channel>
</rss>
