<?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: addupe</title>
    <description>The latest articles on DEV Community by addupe (@addupe).</description>
    <link>https://dev.to/addupe</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%2F277304%2F6ad44e36-661f-4509-a112-e20a7714b3b0.jpeg</url>
      <title>DEV Community: addupe</title>
      <link>https://dev.to/addupe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/addupe"/>
    <language>en</language>
    <item>
      <title>Search with Fuse.js</title>
      <dc:creator>addupe</dc:creator>
      <pubDate>Mon, 10 Feb 2020 01:20:10 +0000</pubDate>
      <link>https://dev.to/addupe/search-with-fuse-js-2npj</link>
      <guid>https://dev.to/addupe/search-with-fuse-js-2npj</guid>
      <description>&lt;p&gt;Fuse.js is a lightweight JavaScript search library that supports fuzzy search. The docs are great and you can play around with searching a sample of your data in the live demo. And it's &lt;em&gt;open-source.&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;docs: &lt;a href="https://fusejs.io/"&gt;https://fusejs.io/&lt;/a&gt;&lt;br&gt;
github: &lt;a href="https://github.com/krisk/fuse"&gt;https://github.com/krisk/fuse&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A few weeks ago, I built an application that found a single random poem from a single word input by the user. I used an external API that already had some search functionality built in. One of the endpoints allowed me to search by line and I then worked out the randomization and format of the response data. &lt;/p&gt;

&lt;p&gt;This week, for the purposes of learning how Fuse.js works, I made a simple React web app using an array of objects to store all of the Sonnets of William Shakespeare and installed Fuse.js to search my array of objects for a Sonnet including a given query. &lt;/p&gt;

&lt;p&gt;here's the npm install: npm install fuse.js&lt;/p&gt;

&lt;p&gt;We've got a simple App component that renders our Search component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import Search from './Search';
import './App.css';

function App() {
  return (
    &amp;lt;Search /&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our Search component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from 'react';
import Highlight from 'react-highlighter';
import { fuse } from './fuse/fuse-helper';

function Search() {
  const [searchTerm, setSearchTerm] = useState('');
  const [results, setResults] = useState([]);

  const handleChange = event =&amp;gt; {
    setSearchTerm(event.target.value);
  };

  const handleEnter = async (event) =&amp;gt; {
    if (event.keyCode === 13) {
      const foundSonnets = await fuse.search(searchTerm);
      setResults(foundSonnets);
    }
  };

  return (
    &amp;lt;div style={{ margin: 20 }}&amp;gt;
      &amp;lt;h2&amp;gt;fuse.js&amp;lt;/h2&amp;gt;
      &amp;lt;input
        type="text"
        placeholder="search"
        value={searchTerm}
        onChange={handleChange}
        onKeyDown={handleEnter}
      /&amp;gt;
      {results.map((result, i) =&amp;gt; {
        console.log('fuse matches:', result.matches);
        return (
          &amp;lt;div style={{ margin: 20 }} key={i}&amp;gt;
            &amp;lt;Highlight search={searchTerm} style={{ fontWeight: "bold" }}&amp;gt;{result.item.title}&amp;lt;/Highlight&amp;gt;
            {result.item.lines.map((line, i) =&amp;gt; {
              return (
                &amp;lt;div key={i}&amp;gt;
                  &amp;lt;Highlight search={searchTerm}&amp;gt;{line}&amp;lt;/Highlight&amp;gt;
                &amp;lt;/div&amp;gt;
              )
            })}
          &amp;lt;/div&amp;gt;
        )
      })}
    &amp;lt;/div&amp;gt;
  );
}

export default Search;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The result looks like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YJ6uRSMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/ORiKoBr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YJ6uRSMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/ORiKoBr.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I set up a fuse folder in my src directory to hold my temporary Sonnet data and my fuse helpers. (Given a larger app made for actual production, I'd probably want this data in some kind of database, but the array storage works for our purposes). My file structure looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
  fuse/
    fuse-helper.js
    sonnets.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The structure of our sonnet storage looks like this. This is the first sonnet, stored in an array of sonnets as an object with keys &lt;code&gt;title&lt;/code&gt;, &lt;code&gt;author&lt;/code&gt;, &lt;code&gt;lines&lt;/code&gt;, &lt;code&gt;linecount&lt;/code&gt;. Every object follows this pattern.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sonnets = [
  {
    "title": "Sonnet 1: From fairest creatures we desire increase",
    "author": "William Shakespeare",
    "lines": [
      "From fairest creatures we desire increase,",
      "That thereby beauty's rose might never die,",
      "But as the riper should by time decease,",
      "His tender heir might bear his memory:",
      "But thou contracted to thine own bright eyes,",
      "Feed'st thy light's flame with self-substantial fuel,",
      "Making a famine where abundance lies,",
      "Thy self thy foe, to thy sweet self too cruel:",
      "Thou that art now the world's fresh ornament,",
      "And only herald to the gaudy spring,",
      "Within thine own bud buriest thy content,",
      "And tender churl mak'st waste in niggarding:",
      "  Pity the world, or else this glutton be,",
      "  To eat the world's due, by the grave and thee."
    ],
    "linecount": "14"
  },
  {...},
  {...},
  {...},
];

const _sonnets = sonnets;
export { _sonnets as sonnets };
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In our fuse helper file, I imported Fuse from fuse.js and the sonnet data variable. When using fuse, you have access to these 'options' which determine the parameters of the search, the sort style, the information you receive about the matches in the generated search results, and the threshold of the search. I recommend looking into these options in fuse's docs and playing around with them in the live demo. The key ones for us to pay attention to here are the &lt;code&gt;keys&lt;/code&gt; and the &lt;code&gt;threshold&lt;/code&gt;. &lt;code&gt;shouldSort&lt;/code&gt; is also important, because typically, you want to sort by the closest matches. Set this to true. &lt;code&gt;Keys&lt;/code&gt; is what lets fuse know what keys to access. Here we have title and lines, meaning that the sonnet fuse will look through our array of sonnet objects and find any sonnet that has the target word in the title key values or in the line key values. &lt;code&gt;Threshold&lt;/code&gt; is what allows for the fuzzy search. &lt;code&gt;0.0&lt;/code&gt; would mean you need an exact match and &lt;code&gt;0.6&lt;/code&gt; would be the setting for fuzzy as it gets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Fuse  from 'fuse.js';
import { sonnets } from './sonnets';

const options = {
  shouldSort: true,
  includeMatches: true,
  threshold: 0.1,
  location: 0,
  distance: 100,
  maxPatternLength: 32,
  minMatchCharLength: 1,
  keys: [
    "title",
    "lines"
  ]
};

const fuse = new Fuse(sonnets, options);

const _fuse = fuse;
export { _fuse as fuse };
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Searching for the word &lt;code&gt;star&lt;/code&gt; yields this response:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ype_Q8uD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/16OktlF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ype_Q8uD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/16OktlF.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;*The highlighting effect is from react-highlighter, a pretty cool little tool.&lt;/p&gt;

&lt;p&gt;You'll notice if you look again at the search component, that I console logged the fuse matches for each result. Let's take a look at the logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log('fuse matches:', result.matches);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2607e1JD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/UuCw3dh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2607e1JD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/UuCw3dh.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we want to see the whole fuse results array: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i4_l7STz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/CpSJynU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i4_l7STz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/CpSJynU.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We see that we get back an array with the matching &lt;code&gt;item&lt;/code&gt; and the &lt;code&gt;matches&lt;/code&gt; (if we set the includeMatches prop to true). And we render accordingly, knowing that each found object will be listed as an item in our results array.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;fin&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>'Hello World' in C++ for the JavaScripter</title>
      <dc:creator>addupe</dc:creator>
      <pubDate>Mon, 03 Feb 2020 01:18:27 +0000</pubDate>
      <link>https://dev.to/addupe/hello-world-in-c-for-the-javascripter-dc3</link>
      <guid>https://dev.to/addupe/hello-world-in-c-for-the-javascripter-dc3</guid>
      <description>&lt;h3&gt;
  
  
  JavaScript Recap
&lt;/h3&gt;

&lt;p&gt;Declaring a namespace / variable&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XAt1Gk0Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/swfkzA9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XAt1Gk0Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/swfkzA9.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Function body&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DVzXhyZ1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/8hbtkDF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DVzXhyZ1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/8hbtkDF.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Printing command&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P8VLTwl9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/lyZsUaO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P8VLTwl9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/lyZsUaO.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Execution&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iTN0SW-y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/APCog6s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iTN0SW-y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/APCog6s.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  C++ Intro
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Compiling script&lt;/em&gt;&lt;br&gt;
In JavaScript, our code is read by interpreters in the browser at run time. C++ is read by a compiler which converts the language into machine code before program run. But for the compiler to have everything it needs to interpret the given code. This first line &lt;code&gt;#include &amp;lt;iostream&lt;/code&gt; is read by the preprocessor as a &lt;code&gt;preprocessor directive&lt;/code&gt; which runs before actual compilation of the code and allows the preprocessor to paste in any needed files. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yP0zPFMO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/UJhg0fK.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yP0zPFMO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/UJhg0fK.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Namespace declaration (sort of)&lt;/em&gt;&lt;br&gt;
Okay, here our namespace declaration contains a two parter. There's the namespace for the function itself, which is actually &lt;code&gt;main()&lt;/code&gt; in this example and then there's the namespace declaration for any methods/other functions that will be utilized in our file. The &lt;code&gt;using namespace std;&lt;/code&gt; as I understand it, is another kind of file that contains methods defined as prefixes, like a library in JavaScript, and we declare that we will be using that 'library' of functions. &lt;code&gt;cout&lt;/code&gt; here exists within the &lt;code&gt;std&lt;/code&gt; set of functions. If we needed a function that existed within a different 'file', we would include that corresponding namespace.&lt;br&gt;
*There are two ways of doing this and this one is actually not best practice (more on that below)&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ar8mgasg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/KFCfMsC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ar8mgasg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/KFCfMsC.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Function body&lt;/em&gt;&lt;br&gt;
The meat of our function. The code that will be executed inside of our function. Still uses { and }.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KVub-A5A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/LF69leE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KVub-A5A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/LF69leE.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Execution done by compiler&lt;/em&gt;&lt;br&gt;
We get our first glimpse at &lt;code&gt;main()&lt;/code&gt;, which is a special function in all C++ programs. This is our actual function declaration. It is also our execution, because in C++ the main function, no matter where it is located in our file, will always be called first by the compiler. The &lt;code&gt;int&lt;/code&gt; here is what defines the &lt;code&gt;type&lt;/code&gt; of function. In JavaScript, we would have our variable declaration keyword either: 'let' or 'const'. Int in C++ is a 'fundamental variable type' It is short for integer and describes what the function will return. It's a little confusing when just printing something, but there's a 0 return that is usually included that gives a signal that no errors are included. I've left it out of these first examples, but you'll see it in the revised 'Hello World' solution further down.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nQFw6jhq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/ayBor27.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nQFw6jhq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/ayBor27.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Printing command&lt;/em&gt;&lt;br&gt;
This is the equivalent to our console log. &lt;code&gt;cout&lt;/code&gt; tells our program to print and the &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; gives direction to what will be printed. In our case, our dearly beloved: 'Hello World'.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cjPlsSHw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/MuPhTP8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cjPlsSHw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/MuPhTP8.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---1EBg2j9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/VJVt7SC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---1EBg2j9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/VJVt7SC.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Input Output Visualization&lt;/em&gt;&lt;br&gt;
Back to &lt;code&gt;iostream&lt;/code&gt; briefly, this is a visualization I found useful in considering what &lt;code&gt;standard input and output operations&lt;/code&gt; are and how they're run in C++. I've heard the analogy of water and oil flowing through a pipe. I'll link the Quora response that explained this more in depth.^1&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rvx3d8_4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/mBCGeYI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rvx3d8_4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/mBCGeYI.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Abstraction Scale&lt;br&gt;
In my research, I've read C++ classified as both a high level language and a mid level language. What I understand is it's still high level, meaning that it uses a great deal of abstraction from machine code to let us use language syntax and variable names as words, etc. But it's a little lower level than JavaScript.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8ycTCwP---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/5mcoOMr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8ycTCwP---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/5mcoOMr.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is C++ used for? &lt;br&gt;
&lt;em&gt;like everything&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;video games&lt;/li&gt;
&lt;li&gt;MySQL built with C++&lt;/li&gt;
&lt;li&gt;operating systems&lt;/li&gt;
&lt;li&gt;compilers&lt;/li&gt;
&lt;li&gt;3d modeling&lt;/li&gt;
&lt;li&gt;adobe systems&lt;/li&gt;
&lt;li&gt;Curiosity rover's autonomy system&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oprb2Xu9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/mM0HX1A.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oprb2Xu9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/mM0HX1A.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Another solution&lt;/em&gt;&lt;br&gt;
You'll notice the namespace &lt;code&gt;std&lt;/code&gt; is included directly alongside the method that is pulled from that library. This is considered better practice, because you avoid ambiguity when including multiple libraries in a single file of code. This example also includes a &lt;code&gt;return 0&lt;/code&gt; which I still have a lot of questions about myself, but I understand is kind of like an error check and ends the code block, similarly to the way returning in JavaScript defines a function and acts as a break point.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pdbuCru4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/SsnPoJc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pdbuCru4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/SsnPoJc.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j9TB8FDD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/N19m4V7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j9TB8FDD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/N19m4V7.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Side by side&lt;/em&gt;&lt;br&gt;
&lt;em&gt;double double toil and trouble&lt;/em&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MStBnCdl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/TSivPwy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MStBnCdl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/TSivPwy.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading!&lt;/em&gt;&lt;br&gt;
If anyone finds any errors I've made here or has suggestions, please let me know in the comments below. I'm trying to get a better grasp on C++ coming from a JavaScript world.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uoAfnFbM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/bVdzIOn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uoAfnFbM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/bVdzIOn.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;^[1] &lt;a href="https://www.quora.com/What-is-the-purpose-of-the-C-header-file-iostream"&gt;quora streams&lt;/a&gt;&lt;br&gt;
***&lt;a href="http://www.cplusplus.com/doc/tutorial/program_structure/"&gt;and a great C++ resource&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Differences between PostgreSQL and MySQL</title>
      <dc:creator>addupe</dc:creator>
      <pubDate>Mon, 27 Jan 2020 07:25:13 +0000</pubDate>
      <link>https://dev.to/addupe/differences-between-postgresql-and-mysql-3jck</link>
      <guid>https://dev.to/addupe/differences-between-postgresql-and-mysql-3jck</guid>
      <description>&lt;h2&gt;
  
  
  Technical Similarities
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;use SQL (Structured Query Language)&lt;/li&gt;
&lt;li&gt;are relational databases&lt;/li&gt;
&lt;li&gt;with schemas&lt;/li&gt;
&lt;li&gt;tables (similar format)&lt;/li&gt;
&lt;li&gt;familiar MySQL data-types&lt;/li&gt;
&lt;li&gt;queries&lt;/li&gt;
&lt;li&gt;CLI (Command Line Interface)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Technical Differences
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Data type variations: BYTEA instead of BLOB, TEXT instead of LONGTEXT and MEDIUMTEXT, INTEGER sizing, UUID in postgres not in mysql&lt;/li&gt;
&lt;li&gt;CLI syntax&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Postgres object-relational features (ORDBMS): &lt;br&gt;
*act as a middle man between object oriented databases (info represented by objects) and relational databases / couples well with an object oriented programming language like Java, C++, Ruby, Python&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;table inheritance[1]&lt;/li&gt;
&lt;li&gt;function creation / overloading[2]&lt;/li&gt;
&lt;li&gt;foreign data wrappers&lt;/li&gt;
&lt;li&gt;others*: more than one schema per database, ACID compliance[3], materialized views,constraint checking, lateral joins, variadic arguments, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I recommend checking out Dian Fay's Ultimate Blog Post here for more detail:(&lt;a href="https://dev.to/dmfay/the-ultimate-postgres-vs-mysql-blog-post-1l5f"&gt;https://dev.to/dmfay/the-ultimate-postgres-vs-mysql-blog-post-1l5f&lt;/a&gt;)&lt;/p&gt;
&lt;h2&gt;
  
  
  Installing
&lt;/h2&gt;

&lt;p&gt;(linux commands) &lt;/p&gt;

&lt;p&gt;PostgreSQL: sudo apt install postgresql-10&lt;br&gt;
MySQL: sudo apt install mysql-server&lt;/p&gt;
&lt;h2&gt;
  
  
  Starting
&lt;/h2&gt;

&lt;p&gt;PostgreSQL: sudo -u postgres psql&lt;br&gt;
MySQL: sudo mysql -u root&lt;/p&gt;
&lt;h3&gt;
  
  
  User Roles
&lt;/h3&gt;

&lt;p&gt;PostgreSQL: default user = ‘postgres’, password needs to be set&lt;br&gt;
MySQL: default user = ‘root’, password ''&lt;/p&gt;
&lt;h4&gt;
  
  
  Altering Roles
&lt;/h4&gt;

&lt;p&gt;PostgreSQL: &lt;br&gt;
&lt;code&gt;ALTER USER postgres with encrypted password 'postgres';&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
MySQL: &lt;br&gt;
&lt;code&gt;ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘newpassword’;&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Running a schema file
&lt;/h3&gt;

&lt;p&gt;PostgreSQL: sudo -u postgres psql -f [file.sql]&lt;br&gt;
MySQL: sudo mysql -u root &amp;lt; [file.sql]&lt;/p&gt;
&lt;h3&gt;
  
  
  Common CLI commands
&lt;/h3&gt;

&lt;p&gt;PostgreSQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list databases: \l
connect: \c [database_name]
list tables: \dt or \dt+
describe table: \d [tablename];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;MySQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list databases: show databases;
connect: use [database_name];
list tables: show tables;
describe table: describe [tablename];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Tables structure is the same!
&lt;/h3&gt;

&lt;p&gt;*data-type usage may be different, tab formatting may vary&lt;/p&gt;

&lt;p&gt;PostgreSQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
 id INT GENERATED ALWAYS AS IDENTITY,
 username VARCHAR(50) NOT NULL,
 email VARCHAR(50) NOT NULL,
 PRIMARY KEY (id)
);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;MySQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 username VARCHAR(255) NOT NULL,
 email VARCHAR(255) NOT NULL
 PRIMARY KEY (id)
);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Raw queries are basically the same
&lt;/h3&gt;

&lt;p&gt;Still SQL!&lt;/p&gt;

&lt;p&gt;PostgreSQL: &lt;code&gt;SELECT * FROM tablename&lt;/code&gt;&lt;br&gt;
MySQL: &lt;code&gt;SELECT * FROM tablename&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Quitting
&lt;/h3&gt;

&lt;p&gt;PostgreSQL: \q&lt;br&gt;
MySQL: quit; OR exit;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X6N62tLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/-gJIq1_EB-RtoqzAoc0VLJP1pHHlWplyI91iU67Wa_bg_ae6dw4Anfz8MMRtq2t7YJx7O-03mgfgsrGhEIGbYuJQogSst_RC79Q4vYEtVHRH0IL3NoOnyq5OJi3vmXy_U96OOTy-xNo" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X6N62tLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/-gJIq1_EB-RtoqzAoc0VLJP1pHHlWplyI91iU67Wa_bg_ae6dw4Anfz8MMRtq2t7YJx7O-03mgfgsrGhEIGbYuJQogSst_RC79Q4vYEtVHRH0IL3NoOnyq5OJi3vmXy_U96OOTy-xNo" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PostgreSQL or MySQL?&lt;/p&gt;

&lt;p&gt;Consider if you'll need access to PostgreSQL's added Object Oriented features. Think about how much you value open source. PostgreSQL is truly open source, whereas MySQL is only 'partially' open source. Figure out how you'll install, open your CLI, run schema file and then you'll use PostgreSQL almost the same way you'd use MySQL with some altered command lines, added functionality, and modified data-types. You can ignore any PostgreSQL features you don't need and use them if and when you need them.&lt;/p&gt;

&lt;p&gt;[1]TABLE INHERITANCE: Let’s say you are storing major cities in the US. You have a table cities and a table capitals. Naturally, capitals are also cities, so you want some way to show the capitals implicitly when you list all cities. a row of capitals inherits all columns (name, population, and altitude) from its parent, cities&lt;br&gt;
[2]FUNCTION OVERLOADING: Postgres can store functions in its database and more than one function may be defined with the same name, so long as the arguments they take are different. This renaming is called overloading. The one matching the argument datatype will be the stored function called and evaluated.&lt;br&gt;
[3]ACID: (Atomicity, Consistency, Isolation, Durability) refers to a standard set of properties that guarantee database transactions are processed reliably. ... An ACID-compliant DBMS ensures that the data in the database remains accurate and consistent despite any such failures&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Google 'Speech' APIs</title>
      <dc:creator>addupe</dc:creator>
      <pubDate>Mon, 20 Jan 2020 05:40:35 +0000</pubDate>
      <link>https://dev.to/addupe/google-machine-learning-speech-apis-c8j</link>
      <guid>https://dev.to/addupe/google-machine-learning-speech-apis-c8j</guid>
      <description>&lt;p&gt;Google Cloud offers two APIs as AI &amp;amp; Machine Learning Products.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cloud Text-To-Speech&lt;/li&gt;
&lt;li&gt;Cloud Speech-To-Text&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;From the API docs: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;'Google Cloud Text-to-Speech converts text into human-like speech in more than 180 voices across 30+ languages and variants. It applies groundbreaking research in speech synthesis (WaveNet) and Google's powerful neural networks to deliver high-fidelity audio.'&lt;/p&gt;

&lt;p&gt;'Google Cloud Speech-to-Text enables developers to convert audio to text by applying powerful neural network models in an easy-to-use API.'&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Who remembers this?&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CKsxmTe8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.rtsoftwares.com/text-to-speech/voices/images/text-to-speech-voices.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CKsxmTe8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.rtsoftwares.com/text-to-speech/voices/images/text-to-speech-voices.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We've obviously progressed.&lt;br&gt;
There's Siri and Alexa and APIs like these available for use right in our applications.&lt;/p&gt;

&lt;p&gt;Google's API docs are also very user friendly compared to other API docs I've used. (Let me know your opinions on this below)&lt;/p&gt;

&lt;p&gt;In the docs*, you can test the API directly with an example JSON body to send to the provided endpoint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TIX8dY5y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/BogVK8I.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TIX8dY5y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/BogVK8I.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "audioConfig": {
    "audioEncoding": "LINEAR16",
    "pitch": 0,
    "speakingRate": 1
  },
  "input": {
    "text": "Nay, answer me: stand, and unfold yourself."
  },
  "voice": {
    "languageCode": "en-GB",
    "name": "en-GB-Wavenet-A"
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cXmWt2sd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/jPiWJiu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cXmWt2sd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://i.imgur.com/jPiWJiu.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "audio": {
    "content": "/* Your audio */"
  },
  "config": {
    "enableAutomaticPunctuation": true,
    "encoding": "LINEAR16",
    "languageCode": "en-US",
    "model": "default"
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Google refers to the transformation process in both tools as Speech Synthesis: 'The process of translating text input into audio data is called synthesis and the output of synthesis is called synthetic speech'. &lt;/p&gt;

&lt;p&gt;These are the three methods Google writes of implementing in their synthesis processes:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Synchronous Recognition (REST and gRPC) sends audio data to the Speech-to-Text API, performs recognition on that data, and returns results after all audio has been processed. Synchronous recognition requests are limited to audio data of 1 minute or less in duration.&lt;/p&gt;

&lt;p&gt;Asynchronous Recognition (REST and gRPC) sends audio data to the Speech-to-Text API and initiates a Long Running Operation. Using this operation, you can periodically poll for recognition results. Use asynchronous requests for audio data of any duration up to 480 minutes.&lt;/p&gt;

&lt;p&gt;Streaming Recognition (gRPC only) performs recognition on audio data provided within a gRPC bi-directional stream. Streaming requests are designed for real-time recognition purposes, such as capturing live audio from a microphone. Streaming recognition provides interim results while audio is being captured, allowing result to appear, for example, while a user is still speaking.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;(some notes on encoding)&lt;/p&gt;

&lt;p&gt;The text-to-speech API generates a raw audio file as a base64 encoded string. This encoded string must be decoded into a playable audio file. Something like an MP3.&lt;/p&gt;

&lt;p&gt;When using the speech-to-text API example upload, the audio conversion is handled for you in a gooey made by google, but when sending an API request in code, you'll have to consider the encoding of your audio received from the user. See this note and link on encoding: 'Audio data is binary data, so you will need to convert such binary data into text using Base64 encoding.' &lt;/p&gt;

&lt;p&gt;Tbh, I have a surface level knowledge of encoding formats, so I'll link the wikipedia article as a jumping off point for everyone so I don't stick my foot in my ear here.&lt;/p&gt;

&lt;p&gt;Watch out for your encoding types. (And leave technical insight in the comments pls.)&lt;/p&gt;

&lt;p&gt;What's interesting to me is that&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;this is an awesome pair of tools that look! we have access to&lt;/li&gt;
&lt;li&gt;the use cases are great. we already see them with google translate and the like, but also could be used to make our apps more accessible and make OS we can fall in love with&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What are your ideas? What have you used this for? Where else have you seen it? What are your experiences?&lt;/p&gt;

&lt;p&gt;*&lt;a href="https://cloud.google.com/text-to-speech/"&gt;text to speech docs&lt;/a&gt;&lt;br&gt;
*&lt;a href="https://cloud.google.com/speech-to-text/"&gt;speech to text docs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/Audio_coding_format"&gt;wikipedia audio coding types&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Vim.</title>
      <dc:creator>addupe</dc:creator>
      <pubDate>Mon, 13 Jan 2020 14:29:20 +0000</pubDate>
      <link>https://dev.to/addupe/vim-14ol</link>
      <guid>https://dev.to/addupe/vim-14ol</guid>
      <description>&lt;p&gt;Vim is a highly configurable, free and open-source, text editor and the fifth most popular developing environment in 2019. &lt;/p&gt;

&lt;p&gt;It's completely keyboard driven — which means once you get comfortable with the commands, you can edit at an incredibly efficient speed. There are vim plugins and extensions for the browser and for other popular editors like VsCode that allow you to use these same commands in other environments.&lt;/p&gt;

&lt;p&gt;Vim seems to have something like a cult-classic kind of following. I remember when I began my coding journey, it was one of the first things I learned about and it felt like magic to me —&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BjnWksfj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.theconversation.com/files/162837/original/image-20170328-21254-1cddjy3.jpg%3Fixlib%3Drb-1.1.0%26q%3D45%26auto%3Dformat%26w%3D496%26fit%3Dclip" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BjnWksfj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.theconversation.com/files/162837/original/image-20170328-21254-1cddjy3.jpg%3Fixlib%3Drb-1.1.0%26q%3D45%26auto%3Dformat%26w%3D496%26fit%3Dclip" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and was just as hard to figure out how to get out of...&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This&lt;/em&gt; is a common memeable issue with beginner Vim users. You get into vim and you can't get out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--knlHdPC0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.chzbgr.com/full/4169024768/h5280284C/" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--knlHdPC0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.chzbgr.com/full/4169024768/h5280284C/" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Computer exit holodeck&lt;br&gt;
Computer exit holodeck&lt;br&gt;
Computer exit&lt;br&gt;
Computer ? &lt;/p&gt;

&lt;p&gt;So first things first:&lt;/p&gt;

&lt;p&gt;The command is &lt;code&gt;:q&lt;/code&gt;&lt;br&gt;
If you're in insert mode first &lt;code&gt;esc&lt;/code&gt;&lt;br&gt;
If you press &lt;code&gt;ctrl&lt;/code&gt; + &lt;code&gt;s&lt;/code&gt; and haven't disabled the sticky in your startup script, you'll have to press &lt;code&gt;ctrl&lt;/code&gt; + &lt;code&gt;q&lt;/code&gt; before you can then &lt;code&gt;:q&lt;/code&gt;&lt;br&gt;
&lt;code&gt;:&lt;/code&gt; colons follow most commands &lt;br&gt;
and &lt;code&gt;!&lt;/code&gt; at the end of a command forces it &lt;br&gt;
&lt;code&gt;:q!&lt;/code&gt; is the equivalent of force quit&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gAHn_rJg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media0.giphy.com/media/HCBDuHiSJaMqQ/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gAHn_rJg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media0.giphy.com/media/HCBDuHiSJaMqQ/source.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vim is really useful and worth learning the basics of in case you need to use it. A lot of programs will have it as a default editing tool. The other day I was working on an AWS deployment and the shell used vim by default. Luckily, I already knew how to make the necessary exits, write and exit the program. &lt;/p&gt;

&lt;p&gt;I will be reviewing some of the basic commands found in vimtutor, but I recommend starting there if you're new to vim and maybe repeating it a couple of times in the beginning.^1&lt;/p&gt;

&lt;p&gt;Other than exiting, &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;entering&lt;/li&gt;
&lt;li&gt;movement&lt;/li&gt;
&lt;li&gt;insertion&lt;/li&gt;
&lt;li&gt;deletion&lt;/li&gt;
&lt;li&gt;writing (saving)&lt;/li&gt;
&lt;li&gt;replacement &lt;/li&gt;
&lt;li&gt;undo/redo&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;are pretty important text editing needs you'll come across as a beginner vim user. &lt;/p&gt;

&lt;p&gt;Entering vim is done through the terminal, as a command &lt;code&gt;vim [filename]&lt;/code&gt;&lt;br&gt;
So vim with a new file name like &lt;code&gt;vim program-dixon-hill&lt;/code&gt; would open a new, empty file and a vim command with an existing file name would open &lt;em&gt;that&lt;/em&gt; vim file &lt;code&gt;vim holodeck&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To move around in vim you want to make sure you're in normal mode, not in insertion mode, meaning you can't type anything and use &lt;code&gt;j&lt;/code&gt; to move down, &lt;code&gt;k&lt;/code&gt; to move up, &lt;code&gt;h&lt;/code&gt; to move left, and &lt;code&gt;l&lt;/code&gt; to move right.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8KXzCgCu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i1.wp.com/iangoprek.net/wp-content/uploads/2017/01/hjkl.png%3Fresize%3D302%252C132%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8KXzCgCu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i1.wp.com/iangoprek.net/wp-content/uploads/2017/01/hjkl.png%3Fresize%3D302%252C132%26ssl%3D1" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I say &lt;code&gt;insertion&lt;/code&gt; mode vs. &lt;code&gt;normal&lt;/code&gt; mode, Vim as 12 different editing modes, 6 basic modes w/ variations:&lt;/p&gt;

&lt;p&gt;(This is from Vim's wikipedia page)^2&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Normal mode - used for editor commands. This is also the default mode, unless the insertmode option is specified.&lt;/li&gt;
&lt;li&gt;Visual mode - similar to normal mode, but used to highlight areas of text. Normal commands are run on the highlighted area, which for an instance can be used to move or edit a selection.&lt;/li&gt;
&lt;li&gt;Select mode - works similarly to visual mode. However, if a printable character, carriage return, or newline (or line feed) is entered, Vim inserts the character, and starts insert mode.[32]&lt;/li&gt;
&lt;li&gt;Insert mode - similar to editing in most modern editors. In insert mode, buffers can be modified with the text inserted.&lt;/li&gt;
&lt;li&gt;Command-line or Cmdline mode - supports a single line input at the bottom of the Vim window. Normal commands (beginning with :), and some other specific letters corresponding to different actions (including pattern search and the filter command) activate this mode.&lt;/li&gt;
&lt;li&gt;Ex mode - similarly to Cmdline mode, it takes a single line input at the bottom of the window. However, in Cmdline mode, entering a command exits the mode when the command is executed. Entering a command in Ex mode doesn't cause the mode to change.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Insert mode is entered by using &lt;code&gt;i&lt;/code&gt; and allows you to type in the file.&lt;br&gt;
You can use the arrow keys to navigate when insertion mode, but it's good to get used to toggling back and forth. HJKL are the basic movement keys, but you'll learn other ways of moving around quickly and efficiently in normal mode. For example &lt;code&gt;10j&lt;/code&gt; would move your cursor 10 lines down in normal mode, &lt;code&gt;10k&lt;/code&gt; would move you ten lines up. To escape insertion mode you use &lt;code&gt;esc&lt;/code&gt; used for returning to normal mode from any of these modes.&lt;/p&gt;

&lt;p&gt;Returning to normal mode, you can delete a character by moving the cursor under that character and using &lt;code&gt;x&lt;/code&gt;. To delete an entire word, move to the beginning of that word and use &lt;code&gt;dw&lt;/code&gt; for delete word. To delete multiple words, but not an entire line, use &lt;code&gt;d&amp;lt;number of words&amp;gt;w&lt;/code&gt; like &lt;code&gt;d2w&lt;/code&gt; would delete two words, &lt;code&gt;d3w&lt;/code&gt; would delete three words — and so on. Type &lt;code&gt;d$&lt;/code&gt; to delete to the end of the line and &lt;code&gt;dd&lt;/code&gt; to delete the entire line.&lt;/p&gt;

&lt;p&gt;To write or save what you're doing, &lt;code&gt;:w&lt;/code&gt;. Using &lt;code&gt;:w [filename]&lt;/code&gt; will write a new copy of that file under the given filename, but will not delete your old file. (There are many plugins to use with vim. Here's one I encountered researching this dilemma)[3]&lt;/p&gt;

&lt;p&gt;To replace a character use &lt;code&gt;r&lt;/code&gt; with the cursor placed under it just like you would delete. Capital 'R' will put you in replace mode, replacing each next character with the next one you type until you exit the mode.&lt;/p&gt;

&lt;p&gt;To undo you would use &lt;code&gt;u&lt;/code&gt; for a single change, &lt;code&gt;U&lt;/code&gt; for the whole line. &lt;code&gt;ctrl&lt;/code&gt; + &lt;code&gt;r&lt;/code&gt; is your redo. Vim also keeps track of versions of a file, something like a Git history. I won't go into these details here, but look them up. Also, let me know in the comments below what your best practices are for this and general vim usage.&lt;/p&gt;

&lt;p&gt;If you're like me and you like to use vim for other kinds of writing also, check out this vim for writers article. I usually use the WordProcessorMode plugin when I'm writing or editing something other than code and have found it super useful.[4]&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--amy88v6b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://66.media.tumblr.com/b1a4f737d9a02d8eccdaf8749322634d/tumblr_ovfi4iDUng1tuxekao1_400.gifv" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--amy88v6b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://66.media.tumblr.com/b1a4f737d9a02d8eccdaf8749322634d/tumblr_ovfi4iDUng1tuxekao1_400.gifv" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[1] a program literally called vimtutor and opened with the command &lt;code&gt;vimtutor&lt;/code&gt; — once installed and run will provide a walkthrough tutorial that you can practice keyboard shortcuts by following along with. It's usually installed with vim, but if not, can be easily installed.&lt;br&gt;
&lt;a href="http://www2.geog.ucl.ac.uk/~plewis/teaching/unix/vimtutor"&gt;*view on the web&lt;/a&gt;&lt;br&gt;
[2] &lt;a href="https://en.wikipedia.org/wiki/Vim_text_editor"&gt;vim wiki&lt;/a&gt;&lt;br&gt;
[3] &lt;a href="https://www.vim.org/scripts/script.php?script_id=1928"&gt;saveas plugin&lt;/a&gt;&lt;br&gt;
[4] &lt;a href="https://www.drbunsen.org/writing-in-vim/"&gt;vim 4 writers&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.maketecheasier.com/vim-keyboard-shortcuts-cheatsheet/"&gt;more vim keyboard shortcuts&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
    </item>
    <item>
      <title>Debugging Node.js in VSCode</title>
      <dc:creator>addupe</dc:creator>
      <pubDate>Sun, 15 Dec 2019 21:14:13 +0000</pubDate>
      <link>https://dev.to/addupe/debugging-node-js-in-vscode-10la</link>
      <guid>https://dev.to/addupe/debugging-node-js-in-vscode-10la</guid>
      <description>&lt;p&gt;We use a debugging tool, a 'debugger', to track what’s happening in our code line by line, so we can find out where our errors, 'bugs', live and kindly release those cute little guys from our code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JC3zR1DJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media1.giphy.com/media/dM8fBhhhAmbaU/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JC3zR1DJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media1.giphy.com/media/dM8fBhhhAmbaU/giphy.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Node.js is 'an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside of a browser.'^1 And VSCode has a built in debugging environment for debugging our Node code outside of the browser.^2&lt;/p&gt;

&lt;p&gt;I know that when I started working in Node.js, I was already familiar with debugging in the browser with Google's DevTools when working with the front-end. Comparing the two helped me feel more comfortable with debugging in VSCode. It turns out the tools are very similar. Here's a side by side comparison (gif sources below):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SvetM3yT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://storage.googleapis.com/webfundamentals-assets/updates/2018/01/old-worker-stepping.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SvetM3yT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://storage.googleapis.com/webfundamentals-assets/updates/2018/01/old-worker-stepping.gif" alt=""&gt;&lt;/a&gt;^3&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o_-UD6Pq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://code.visualstudio.com/assets/docs/nodejs/nodejs-debugging/loaded-scripts-explorer.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o_-UD6Pq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://code.visualstudio.com/assets/docs/nodejs/nodejs-debugging/loaded-scripts-explorer.gif" alt=""&gt;&lt;/a&gt;^4&lt;/p&gt;

&lt;p&gt;in browser:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;open devtools panel&lt;/li&gt;
&lt;li&gt;set a breakpoint&lt;/li&gt;
&lt;li&gt;run code&lt;/li&gt;
&lt;li&gt;step through&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;with node in vscode:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;open debugger's panel&lt;/li&gt;
&lt;li&gt;add config / file path&lt;/li&gt;
&lt;li&gt;set a breakpoint&lt;/li&gt;
&lt;li&gt;start debugger&lt;/li&gt;
&lt;li&gt;step through&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Similarities: &lt;br&gt;
Open some kind of panel, set your breakpoints, start your debugger, step through, rinse and repeat.&lt;/p&gt;

&lt;p&gt;Differences:&lt;br&gt;
Location of panel, location of variable tracking, need for a configuration, setting file path, server starting.&lt;/p&gt;

&lt;p&gt;For both the browser DevTools and VSCode's debugging panel, we have to open some kind of tool. In VSCode, there's a little bug icon pointing the way or w/ &lt;code&gt;CTRL + SHIFT + D&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cJHBJvpx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/TB02XFJ/debbuggy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cJHBJvpx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/TB02XFJ/debbuggy.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In VSCode, we have to set up our config and file path. This points our debugger to the file we need to be read. Usually some default will pop up when you click Add Config, but if not, there will be options for the kind of config needed. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SWZal8KX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/7tcmFjk/launch.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SWZal8KX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/7tcmFjk/launch.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Uy7q-rBk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media2.giphy.com/media/p8ehGO66H5PAQ/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Uy7q-rBk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media2.giphy.com/media/p8ehGO66H5PAQ/source.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then you can add any breakpoints you might need just like you would in Google's DevTools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SiJBh8Qf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/bH6BddF/brk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SiJBh8Qf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/bH6BddF/brk.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Start your debugger for the first time with the play button next to where you added your configs. You can restart your debugger later from the debugger's tool bar that will appear. This is also where you'll do your stepping and stopping and playing. If you're unfamiliar with these commands, see the 3rd link below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VCejgBMz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/P1529yk/bugbar.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VCejgBMz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/P1529yk/bugbar.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any variables in the file will be listed in the side panel and you can open up different parts by clicking on the down arrow, as seen below. This is just like the Scope panel in your DevTools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3O5z4dlT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/ZMDvwYG/brk2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3O5z4dlT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/ZMDvwYG/brk2.png" alt=""&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you're using Node.js to build a server and have a config set up to the file that starts your server, the debugger will run this code and restart your server for you, which can become super useful when developing, so you aren't constantly running npm start. Once the server is started, you can go to your page and interact with the page as a user and access any console logs you might have set for GET and POST requests, etc. This will be output in the Debug Console pictured here: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gPEWqSqp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.ibb.co/35X5Nwx/ALm1l90llwpk2-Hz-Mx-WRbj-X68-XYAku-HHKwy-UXBA4-HID7-5-CNnzb-T2dzwu-HFD4-YOLomy-ATKs-Fagf-NIWi2-Ws-UMPn-K0-RVg-KCZ7-QDLq0-Der1-Ka9ok6g0-Nz-Gz-ZSr6-U-ostrwz-Hj-OSl4he-SLeo.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gPEWqSqp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.ibb.co/35X5Nwx/ALm1l90llwpk2-Hz-Mx-WRbj-X68-XYAku-HHKwy-UXBA4-HID7-5-CNnzb-T2dzwu-HFD4-YOLomy-ATKs-Fagf-NIWi2-Ws-UMPn-K0-RVg-KCZ7-QDLq0-Der1-Ka9ok6g0-Nz-Gz-ZSr6-U-ostrwz-Hj-OSl4he-SLeo.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;open, config, break, start, step, rinse, repeat&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vHFPCyvV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media1.giphy.com/media/DoL6h5sd6lqZW/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vHFPCyvV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media1.giphy.com/media/DoL6h5sd6lqZW/source.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[1]&lt;a href="https://nodejs.org/en/docs/"&gt;node.js docs&lt;/a&gt;&lt;br&gt;
[2]&lt;a href="https://nodejs.org/de/docs/guides/debugging-getting-started/"&gt;node.js inspect&lt;/a&gt;&lt;br&gt;
[3]&lt;a href="https://developers.google.com/web/updates/2018/01/devtools"&gt;DevTools gif&lt;/a&gt;&lt;br&gt;
[4]&lt;a href="https://code.visualstudio.com/docs/nodejs/nodejs-debugging"&gt;VSCode gif&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React JS: Stateful vs Stateless Components</title>
      <dc:creator>addupe</dc:creator>
      <pubDate>Sun, 08 Dec 2019 21:00:04 +0000</pubDate>
      <link>https://dev.to/addupe/react-state-4oip</link>
      <guid>https://dev.to/addupe/react-state-4oip</guid>
      <description>&lt;p&gt;Components are just the parts of our application in React JS. Each component needs to handle data, either to render it on the page or to pass it along to another component. The way that a component deals with data defines if that app is stateful or stateless. &lt;/p&gt;

&lt;p&gt;Stateful components deal with data in 'state,' keeping a reference to a set of data that may change, while stateless components keep receive data in the form of props (short for properties) received from a parent component or a lineage of parent components, at least one of these parent components being stateful themselves.&lt;/p&gt;

&lt;p&gt;Let's say we build a little web app to keep track of our personal reading list:&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%2Fi.ibb.co%2FJnb739j%2Fbooks.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%2Fi.ibb.co%2FJnb739j%2Fbooks.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This small app would have a few small components. This one has three: &lt;/p&gt;

&lt;p&gt;1) The main (stateful) app component which tracks all data and renders other child components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ReadingApp extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
        //these might change
        //add books, finish reading books
      books: this.props.books,
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) A stateless ReadingList component that contains a child component and passes the data received from the main ReadingApp along:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ReadingList = (props) =&amp;gt; {
  return (
    &amp;lt;table&amp;gt;
    &amp;lt;tbody&amp;gt;
      {books.map(book =&amp;gt; {
        return &amp;lt;ReadingListEntry book={book} /&amp;gt;
      })}   
    &amp;lt;/tbody&amp;gt;
  &amp;lt;/table&amp;gt;
  );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) This ReadingListEntry component, of which a new instance of is created each time another book is added to the state and which itself includes a toggling state changing click event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ReadingListEntry extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showQuote: false,
    };
  }

render() {
    const { title, cover, quote } = this.props.book;
    return (
      &amp;lt;tr onClick={() =&amp;gt; this.setState({ showQuote: !this.state.showQuote})}&amp;gt;
        &amp;lt;div className="book-title-container"&amp;gt;
        &amp;lt;td className="book-title"&amp;gt;{title}&amp;lt;/td&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;td&amp;gt;
          &amp;lt;img src={cover}/&amp;gt;
        &amp;lt;/td&amp;gt;
        {this.state.showQuote ? &amp;lt;td className="book-quote"&amp;gt;{quote}&amp;lt;/td&amp;gt; : null}
      &amp;lt;/tr&amp;gt;
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that our two stateful components are written in the ES6 Class instantiation patterns. Stateful components are referred to as Class Components and are extended from React.Component, inheriting its stateful reactivity from the React library. Stateful components can also receive props though and in my examples, the state is defined with a value accessed from the passed down props. &lt;/p&gt;

&lt;p&gt;Stateless components only receive props and are written as Function declarations. Stateless components are static and often act like containers in an application. They themselves do not need to have data re-rendered, but can pass along changing data. &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%2Fs27.aconvert.com%2Fconvert%2Fp3r68-cdx67%2Fms891-wn4kg.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%2Fs27.aconvert.com%2Fconvert%2Fp3r68-cdx67%2Fms891-wn4kg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The main ReadingApp component needs to be stateful to render books as they are added, deleted, or order swapped. &lt;/p&gt;

&lt;p&gt;The ReadingList component can be stateless, because it's main responsiblity is acting as a container for the ReadingListEntry components it renders with its inherited data passed right along. ReadingListEntry again, is stateful, for the clicks. A showQuote property is set on the ReadingListEntry components' state object, which will be switched back and forth true/false on click and checked before displaying. Seen below:&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%2Fi.ibb.co%2F8Xyf3hN%2Fezgif-com-crop.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%2Fi.ibb.co%2F8Xyf3hN%2Fezgif-com-crop.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In designing our components, it's important to only give state when necessary. If the component is passing data and not meant to be interactive, let it remain stateless. Give parents state over children, unless the child has its' own reason to have state (like in the case of our click function). &lt;/p&gt;

&lt;p&gt;*In React 16.8, Hooks are introduced, which use a form of state without class instantiation. More on that in the docs: &lt;a href="https://reactjs.org/docs/hooks-faq.html#from-classes-to-hooks" rel="noopener noreferrer"&gt;React Hooks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/Q6cgIWU53uE" rel="noopener noreferrer"&gt;ursula k. le guin reading her translation of the tao te ching&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Backbone Getters and Setters</title>
      <dc:creator>addupe</dc:creator>
      <pubDate>Mon, 02 Dec 2019 07:07:57 +0000</pubDate>
      <link>https://dev.to/addupe/backbone-getters-and-trend-setters-203j</link>
      <guid>https://dev.to/addupe/backbone-getters-and-trend-setters-203j</guid>
      <description>&lt;p&gt;Backbone.js is a JavaScript framework that gives our application development some structure, separating our concerns between data (Models) and display (Views). When dealing with our Models in Backbone, we get two handy methods that help us modify and access our data. These are referred to as getters and setters. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;.set()&lt;/code&gt;&lt;br&gt;
&lt;code&gt;.get()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Before we dive in, let's briefly take a peek at the Backbone.js source code:*&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Model = Backbone.Model = function (attributes, options) {
  var attrs = attributes || {};
  options || (options = {});
  this.preinitialize.apply(this, arguments);
  this.cid = _.uniqueId(this.cidPrefix);
  this.attributes = {};
  if (options.collection) this.collection = options.collection;
  if (options.parse) attrs = this.parse(attrs, options) || {};
  var defaults = _.result(this, 'defaults');
  attrs = _.defaults(_.extend({}, defaults, attrs), defaults);
  this.set(attrs, options);
  this.changed = {};
  this.initialize.apply(this, arguments);
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We don't need to go deeply into what is happening here, but let's take some notes: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;attributes are taken in and set&lt;/li&gt;
&lt;li&gt;we have a set of defaults given to the object that we might use&lt;/li&gt;
&lt;li&gt;set is used here&lt;/li&gt;
&lt;li&gt;there’s an object for storing things changed&lt;/li&gt;
&lt;li&gt;dealing with events&lt;/li&gt;
&lt;li&gt;we also do some intializing probably dealing with view&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We might guess that .set() is pretty important to the Model object if it is used in the construction of our big daddy parent object. &lt;/p&gt;

&lt;p&gt;And if we look at the annotations made by Backbone developers on set...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is the core primitive operation of a model, updating the data and notifying anyone who needs to know about the change in state. &lt;em&gt;The heart of the beast.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;.set()&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;is ~60 lines of code&lt;/li&gt;
&lt;li&gt;takes in attributes&lt;/li&gt;
&lt;li&gt;the new value&lt;/li&gt;
&lt;li&gt;modifies the model objects' matching key/value pair&lt;/li&gt;
&lt;li&gt;notifies any event listeners to trigger their operations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;.get()&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;is only 2 lines of code&lt;/li&gt;
&lt;li&gt;is essentially the equivalent of &lt;code&gt;this[key]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;retrieves values from the model attributes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cool.&lt;/p&gt;

&lt;p&gt;Here's a simplified example of how these functions might be used.&lt;/p&gt;

&lt;p&gt;Let's say we have a modeling agency called 'Rlly Legit Models' and our agency website uses backbone. We've just signed a new model and are displaying some information to our page visitors, but were missing some information when we created this 'instance' of model.&lt;/p&gt;

&lt;p&gt;Here's our model:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0Z7JBE6a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://usatftw.files.wordpress.com/2013/12/giphy.gif%3Fw%3D1000" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0Z7JBE6a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://usatftw.files.wordpress.com/2013/12/giphy.gif%3Fw%3D1000" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's his information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const zoolander = new Model({
  name: 'derek',
  headshot: /default.jpg,
  looks: 'really, really, really ridiculously good-looking',
  canTurnLeft: false, 
  walkOffsLost: 1,
  mermaid: 'MERMAN', 
  biggestCompetition: 'Hansel',
  howOld: 'dinosaur',

});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And here's our website currently. &lt;br&gt;
&lt;em&gt;We're also in the process of rebranding from a produce mascot costume distributer service to a rlly legit agency. We've kept some of our previous staff on board.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p4rFQN8L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/frbqg0D/grap.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p4rFQN8L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/frbqg0D/grap.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Oh! We get a notification that Derek has uploaded a new image.&lt;br&gt;
We need to build out some operation that can store that image onto our zoolander object. &lt;/p&gt;

&lt;p&gt;This operation would include .set().&lt;br&gt;
We would call set with two arguments: the attribute to be modified, and the value to assign to that attribute. Something like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;zoolander.set('headshot', '/images/ridiculouslyGoodLooking.jpg')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Our zoolander instance would now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const zoolander = new Model({
  name: 'derek',
  headshot: ‘/images/default.jpg’,
  looks: 'really, really, really ridiculously good-looking',
  canTurnLeft: false, 
  walkOffsLost: 1,
  mermaid: 'MERMAN', 
  biggestCompetition: 'Hansel',
  howOld: 'dinosaur',

});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To avoid complexity, let's assume we have a functioning event listener somewhere in our application that will render new information on the page as it changes. Our changed attribute is somewhere in the computer! How will we get it out and onto the page??!?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--btwElutk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media3.giphy.com/media/vjmSleUsnXU8o/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--btwElutk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media3.giphy.com/media/vjmSleUsnXU8o/source.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our event listener would be using .get(). The information would be retrieved from the model instance and appended to the DOM. Inside the event listener callback we would have some version of this getter:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;this.model.get('headshot'));&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o5YPI9YQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/hLQ9VdJ/pina.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o5YPI9YQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/hLQ9VdJ/pina.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wow, really, really, really ridiculously good looking.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0k0yTkIa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://images6.fanpop.com/image/photos/40700000/Zoolander-david-bowie-40755230-500-216.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0k0yTkIa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://images6.fanpop.com/image/photos/40700000/Zoolander-david-bowie-40755230-500-216.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;*&lt;a href="https://backbonejs.org/docs/backbone.html"&gt;backbone.js annotated source code&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Stacks and Queues Almighty</title>
      <dc:creator>addupe</dc:creator>
      <pubDate>Mon, 25 Nov 2019 04:36:49 +0000</pubDate>
      <link>https://dev.to/addupe/stacks-and-queues-almighty-1971</link>
      <guid>https://dev.to/addupe/stacks-and-queues-almighty-1971</guid>
      <description>&lt;p&gt;&lt;strong&gt;Let's talk Stacks and Queues.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But first, because Stacks and Queues are kinds of data structures:&lt;br&gt;
&lt;em&gt;What is&lt;/em&gt; a data structure?&lt;br&gt;
Are they language specific?&lt;/p&gt;

&lt;p&gt;Data Structures are just the containers our computers store data in.&lt;/p&gt;

&lt;p&gt;When implemented we're talking languages, but when we're talking about the  logical concept and behavior of these structures we're talking Computer Science.*&lt;/p&gt;

&lt;p&gt;Here's the definition from Wikipedia's Data Structure page, which is worth a look: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In computer science, a data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.[^1]&lt;/p&gt;
&lt;/blockquote&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%2Fmedia0.giphy.com%2Fmedia%2FqricWImaylFvy%2Fgiphy.gif%3Fcid%3D790b761166b7737c2265cf358476a6ade26965f837891cb9%26rid%3Dgiphy.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%2Fmedia0.giphy.com%2Fmedia%2FqricWImaylFvy%2Fgiphy.gif%3Fcid%3D790b761166b7737c2265cf358476a6ade26965f837891cb9%26rid%3Dgiphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's just a collection.&lt;br&gt;
Usually characterized by the ways you:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;add to&lt;/li&gt;
&lt;li&gt;remove from&lt;/li&gt;
&lt;li&gt;and access the data within&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And why do we care how our data is stored?&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%2Fmedia0.giphy.com%2Fmedia%2FCvW4U6KwYDWRW%2Fgiphy.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%2Fmedia0.giphy.com%2Fmedia%2FCvW4U6KwYDWRW%2Fgiphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might not be God, like Bruce here. &lt;em&gt;Or Google.&lt;/em&gt;&lt;br&gt;
But even if you don't have 7.7 billion people's information to manage,&lt;br&gt;
it's best to optimize your storage to suit your needs. &lt;/p&gt;

&lt;p&gt;Computers are our friends.&lt;br&gt;
Friends who we can ask to keep track of information for us and do things with that information upon request. And we love computers for it. They can make our lives easier. Thank you, Computer.&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%2Fmedia0.giphy.com%2Fmedia%2FRx6iHHjtJ5baw%2Fgiphy.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%2Fmedia0.giphy.com%2Fmedia%2FRx6iHHjtJ5baw%2Fgiphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But they can only &lt;del&gt;love&lt;/del&gt; help us, if we give them structures they can manage efficiently. &lt;/p&gt;

&lt;p&gt;There are many data structures: Arrays, Linked Lists, Doubly Linked Lists, Records, Trees, Graphs, Trees, Binary Trees, B-Trees, Stacks, Queues, and so on.[^2]&lt;/p&gt;
&lt;h2&gt;
  
  
  Stacks
&lt;/h2&gt;

&lt;p&gt;Remember a data structure is just a way of storing data. Stacks are linear structures (meaning it's elements are sequential/the ordering matters). With stacks, it's useful to think of a stack of books or a stack of pancakes. You always care about the top of the stack (the end of the collection). &lt;/p&gt;

&lt;p&gt;When using a stack, or choosing to use a stack, you're primarily concerned with being able to &lt;strong&gt;push&lt;/strong&gt; and &lt;strong&gt;pop&lt;/strong&gt; from the stack.&lt;/p&gt;

&lt;p&gt;We can also keep track of the size of our stack if we want. And we can &lt;em&gt;peek&lt;/em&gt; at our stack, which just takes a look at the top element in our structure.&lt;/p&gt;

&lt;p&gt;Push = add.&lt;br&gt;
Pop = remove.&lt;br&gt;
Peek = access.&lt;/p&gt;

&lt;p&gt;And we're always adding or removing from the top (which means the end 🙄) of the stack. The common abbreviation of this rule is: &lt;strong&gt;FILO&lt;/strong&gt; First In Last Out, or &lt;strong&gt;LIFO&lt;/strong&gt; Last In First Out. They mean the same thing. &lt;/p&gt;

&lt;p&gt;Here's a push, pop, and size implementation (in pseudoclassical JS).&lt;br&gt;
&lt;sup&gt;(no peek here, but you'd just want to grab the last element)&lt;/sup&gt; &lt;/p&gt;

&lt;p&gt;First, setting up the stack:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Stack = function() {
  this.storage = {};
  this.size = 0;
};

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

&lt;/div&gt;



&lt;p&gt;Push:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Stack.prototype.push = function(value) {
  this.storage[this.size] = value;
  this.size++;
};

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

&lt;/div&gt;



&lt;p&gt;Pop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Stack.prototype.pop = function() {
  const keys = Object.keys(this.storage);
  const popped = this.storage[keys.length - 1];
  delete this.storage[keys.length - 1];
  this.size--;
  return popped;
};

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

&lt;/div&gt;



&lt;p&gt;What's my &lt;del&gt;age&lt;/del&gt; size again?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Stack.prototype.size = function() {
  return this.size &amp;lt; 0 ? 0 : this.size;
};

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

&lt;/div&gt;



&lt;p&gt;Basic applications for the stack structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;undo/redo commands&lt;/li&gt;
&lt;li&gt;word processing &lt;/li&gt;
&lt;li&gt;the call stack (it's own kind of stack structure)&lt;/li&gt;
&lt;li&gt;pancakes&lt;/li&gt;
&lt;li&gt;poltergeisting&lt;/li&gt;
&lt;/ul&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%2Fe3effa51eee72fd900e3-2fb779bd12ec72d4612275342f2c9187.ssl.cf1.rackcdn.com%2Fc6576bab2534178b83e92fea4aabb82f.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%2Fe3effa51eee72fd900e3-2fb779bd12ec72d4612275342f2c9187.ssl.cf1.rackcdn.com%2Fc6576bab2534178b83e92fea4aabb82f.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Implementation is usually done with an Array or Linked List.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What identifies the data structure as a stack in either case is not the implementation but the interface: the user is only allowed to pop or push items onto the array or linked list, with few other helper operations.[^3]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If implementation is done with an Array,&lt;br&gt;
General C.S.* Array structures (not the ones you might see in JavaScript for example) have a set, pre-determined size. This can result in stack overflow! &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%2Fmiro.medium.com%2Fmax%2F1310%2F0%2AGJ_H7_wuWbCYtBjf.png" 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%2Fmiro.medium.com%2Fmax%2F1310%2F0%2AGJ_H7_wuWbCYtBjf.png"&gt;&lt;/a&gt;&lt;br&gt;
^Oh ^no, ^oh ^&lt;del&gt;god&lt;/del&gt; ^bruce&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2F66.media.tumblr.com%2Feaff92895652f4efe0a1fd35f8c342f7%2Ftumblr_mnxxfyIuNH1rlq8k2o1_500.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%2F66.media.tumblr.com%2Feaff92895652f4efe0a1fd35f8c342f7%2Ftumblr_mnxxfyIuNH1rlq8k2o1_500.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Stack overflow is what happens when a program tries to use more memory than is available in the call &lt;em&gt;stack&lt;/em&gt;.^[4]&lt;/p&gt;

&lt;p&gt;Time complexity wise^[5] — stack insertion, removal, access, and size return are constant, because we're only ever concerned &lt;strong&gt;&lt;em&gt;with the top of the stack&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Queues
&lt;/h2&gt;

&lt;p&gt;Queues are very similar to stacks. &lt;br&gt;
[x] Data Structures&lt;br&gt;
[x] Linear&lt;br&gt;
[x] Implemented with your choice of underlying structure&lt;br&gt;
[ ] Only concerned with the end of the collection&lt;br&gt;
[ ] FILO/LIFO&lt;br&gt;
[ ] Like pancakes&lt;br&gt;
[ ] Applications&lt;br&gt;
[x] O(1) time complexity&lt;/p&gt;

&lt;p&gt;Ok, we've got some differences here.&lt;/p&gt;

&lt;p&gt;Queues work by a &lt;strong&gt;FIFO&lt;/strong&gt; First In First Out, or &lt;strong&gt;LILO&lt;/strong&gt; Last In Last Out system. Queues IRL are at the movie theater ticket line, in the grocery store checkout, at the DMV, in the waiting room to the underworld. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/UJR3QgkMnm7tu/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/UJR3QgkMnm7tu/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you remove from the queue, you remove from the beginning of the collection, just like you would from a line of people. When you add, you add to the end of the collection, like you would to the back of a line.&lt;/p&gt;

&lt;p&gt;The names for adding and removing change up on us a bit.&lt;/p&gt;

&lt;p&gt;Enqueue = add.&lt;br&gt;
Dequeue = remove.&lt;/p&gt;

&lt;p&gt;Here's another basic, beginner implementation (also pseudoclassical)^[6]&lt;br&gt;
This time with queues.&lt;/p&gt;

&lt;p&gt;Set up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Queue = function() {
  this.storage = {};
  this.size = 0;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enqueue:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Queue.prototype.enqueue = function(value) {
  this.size++;
  this.storage[this.size] = value;
};

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

&lt;/div&gt;



&lt;p&gt;Dequeue:&lt;br&gt;
&lt;sup&gt;&lt;em&gt;it's midnight on July 21, 2007 and you're first up to buy the Deathly Hallows.&lt;/em&gt;&lt;/sup&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Queue.prototype.dequeue = function() {
  this.size--;
  const keys = Object.keys(this.storage);
  const dequeued = this.storage[keys[0]];
  delete this.storage[keys[0]];
  return dequeued;
};

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

&lt;/div&gt;



&lt;p&gt;Size:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Queue.prototype.size = function() {
  return this.count &amp;lt; 0 ? 0 : this.count;
};

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

&lt;/div&gt;



&lt;p&gt;Basic applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;print queues&lt;/li&gt;
&lt;li&gt;cpu memory&lt;/li&gt;
&lt;li&gt;online shopping&lt;/li&gt;
&lt;li&gt;booking angel olsen tickets online&lt;/li&gt;
&lt;li&gt;searching graphs&lt;/li&gt;
&lt;li&gt;call centers&lt;/li&gt;
&lt;li&gt;rollercoaster tycoon&lt;/li&gt;
&lt;/ul&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%2Fstatic.giantbomb.com%2Fuploads%2Foriginal%2F0%2F5302%2F2500004-q.png" 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%2Fstatic.giantbomb.com%2Fuploads%2Foriginal%2F0%2F5302%2F2500004-q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👏In Conclusion👏&lt;/p&gt;

&lt;p&gt;Same:&lt;br&gt;
[x] Data Structures&lt;br&gt;
[x] Linear&lt;br&gt;
[x] Implemented with your choice of underlying structure&lt;br&gt;
[x] O(1) time complexity&lt;/p&gt;

&lt;p&gt;Not the same:&lt;br&gt;
[ ] Only concerned with the end of the collection&lt;br&gt;
[ ] First/Last rules&lt;br&gt;
[ ] Like pancakes&lt;br&gt;
[ ] Applications&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%2Fthumbs.gfycat.com%2FViciousRecklessAmericanlobster-size_restricted.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%2Fthumbs.gfycat.com%2FViciousRecklessAmericanlobster-size_restricted.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[1]&lt;a href="https://en.wikipedia.org/wiki/Data_structure" rel="noopener noreferrer"&gt;Wikipedia's Data Structure Page&lt;/a&gt;&lt;br&gt;
[2]&lt;a href="https://en.wikipedia.org/wiki/List_of_data_structures" rel="noopener noreferrer"&gt;Big List of Data Structures&lt;/a&gt;&lt;br&gt;
[3]&lt;a href="https://en.wikipedia.org/wiki/Stack_(abstract_data_type)" rel="noopener noreferrer"&gt;Wiki-Stack&lt;/a&gt;&lt;br&gt;
[4]&lt;a href="https://stackoverflow.com/questions/26158/how-does-a-stack-overflow-occur-and-how-do-you-prevent-it" rel="noopener noreferrer"&gt;Meta Overflow&lt;/a&gt;&lt;br&gt;
[5]&lt;a href="https://en.wikipedia.org/wiki/Time_complexity" rel="noopener noreferrer"&gt;Big O&lt;/a&gt;&lt;br&gt;
[6]&lt;a href="https://radialglo.github.io/blog/2014/11/24/understanding-pseudoclassical-inheritance-in-javascript/" rel="noopener noreferrer"&gt;Pseudo-what?&lt;/a&gt;&lt;br&gt;
*Computer Science, my dude.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>computerscience</category>
      <category>beginners</category>
      <category>firstyearincode</category>
    </item>
  </channel>
</rss>
