<?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: Jennifer Lyn Parsons</title>
    <description>The latest articles on DEV Community by Jennifer Lyn Parsons (@jenniferlynparsons).</description>
    <link>https://dev.to/jenniferlynparsons</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%2F8826%2F1587316.png</url>
      <title>DEV Community: Jennifer Lyn Parsons</title>
      <link>https://dev.to/jenniferlynparsons</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jenniferlynparsons"/>
    <language>en</language>
    <item>
      <title>A Refactoring Breakdown</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Mon, 21 Oct 2019 22:54:41 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/a-refactoring-breakdown-5323</link>
      <guid>https://dev.to/jenniferlynparsons/a-refactoring-breakdown-5323</guid>
      <description>&lt;p&gt;I thought it would be interesting and potentially useful to others, to work my way through a refactor. It's not a topic I've run across very often and, especially early on in one's career, it can be challenging to understand exactly how to refactor something. Once code is written and working, trying to see areas where it can be improved can be tricky.&lt;/p&gt;

&lt;p&gt;In addition to showing how a refactor can work, this is giving me a chance to see how much I've been learning. For the purposes of brevity, I'm going to limit this to a single file on a fairly basic project.&lt;/p&gt;

&lt;p&gt;I set up a link directory about a year ago, based off of my Firefox bookmarks. There were plenty of challenges in building the app, not the least of which was that I was relatively new to React, though not to JavaScript or web development in general. In building the app, I focused on just getting the job done and working, even if it meant sacrificing a lot of the more DRY or frankly better ways I could have written it.&lt;/p&gt;

&lt;p&gt;A year on, I've decided to go back to the project and clean it up, give it better structure, and implement my more refined development process. Let's dive into one of these files and see where it goes!&lt;/p&gt;

&lt;h2&gt;
  
  
  Our starting point
&lt;/h2&gt;

&lt;p&gt;The file I'll be using as an example is the list of links that appears under each topic. When I opened the file up, this is what I found:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@reach/router&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;LinkListProps&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../../interfaces&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;LinkList&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;LinkListProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;linkElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;linkID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;linkTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkID&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkTitle&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;links&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;linkElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;})}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;LinkList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Okay, this is not so bad, but I can see some immediate places this can be improved. There's a lot of extra syntax in general, for example. Let me break down the changes I'm making.&lt;/p&gt;

&lt;h3&gt;
  
  
  Swapping Typescript for PropTypes
&lt;/h3&gt;

&lt;p&gt;I've stopped using Typescript in my personal projects over the last year. I think it's awesome and for projects that have a team larger than one and a project significantly more complex than this one, I would argue it might be essential. However, at this level of complexity, Typescript is heavy-handed and adds more to the maintenance time for the project. I would swap it out for more simplified PropTypes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@reach/router&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prop-types&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;LinkList&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;linkElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;linkID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;linkTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkID&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkTitle&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;links&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;linkElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;})}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;LinkList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="nx"&gt;LinkList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;propTypes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="na"&gt;links&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
         &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isRequired&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isRequired&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isRequired&lt;/span&gt;
     &lt;span class="p"&gt;})&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Logic Streamlining
&lt;/h2&gt;

&lt;p&gt;Time to look at the logic itself. In this case, the changes I make aren't going to improve performance in any measurable or meaningful way. It will make the file a little easier to read, which is important. It also reduces the lines of code, which also reduces the tests we'll need to write.&lt;/p&gt;

&lt;p&gt;In retrospect it looks very verbose to have the &lt;code&gt;linkElement&lt;/code&gt; function there when all it actually does is process some simple logic. Originally this had been set up with the anticipation of needing to add more functions to the component and this would separate concerns a bit. However, I've moved toward avoiding premature optimization in my code so this separation is now overkill.&lt;/p&gt;

&lt;p&gt;I'll also note that there's nothing inherently wrong with this code. It compiles properly and the browser does what I would expect it to do with the logic as it's written. With the changes I'm making, what I'm looking to do is improve the readability. I want other developers to be able to read my code as easily as the computer does. So, the changes are about style, more than about substance.&lt;/p&gt;

&lt;p&gt;Before I delete the function entirely, let's see what it would look like cleaned up a bit. Here's our current version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;linkElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;linkID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;linkTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkID&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkTitle&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I would handle this with a ternary as the "else" of the statement is an empty string and even the "if" result is contained on a single line. Let's see what that looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;linkElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;linkID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;linkTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;linkURI&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkID&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkTitle&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That definitely looks even more unnecessary now, right? Okay, now I'll clean up the rest of the file to reflect that change and remove the function. Also note that I don't need to do an explicit return anymore either since I'm using the ternary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@reach/router&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prop-types&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;LinkList&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;links&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;linkURI&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkID&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkURI&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;linkTitle&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt; &lt;span class="p"&gt;)}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;LinkList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="nx"&gt;LinkList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;propTypes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="na"&gt;links&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
         &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isRequired&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isRequired&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isRequired&lt;/span&gt;
     &lt;span class="p"&gt;})&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrap Up
&lt;/h2&gt;

&lt;p&gt;The end result of this refactor accomplishes two major goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Brings the file inline with how I construct my projects now.&lt;/li&gt;
&lt;li&gt;Reduces the amount of code in the file, making it more readable, easier to refactor further as needed, and less prone to bugs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The logic itself is all still there, the functionality of the code didn't change. To the end user, everything will appear exactly the same. The biggest benefit is that the next time a developer (including my future self) opens the file, the level of complexity is much lower, hopefully making it also easier to understand at a glance.&lt;/p&gt;

&lt;p&gt;What makes this a refactor and not just a modification of code? I read this quote from Martin Fowler a while back that sums it up:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So in this case, though the file was small to begin with, I've drastically restructured it while maintaining the external behavior either in how it interacts with other components or in how the user receives the rendered component in the browser.&lt;/p&gt;

&lt;p&gt;With my code cleaned up, I can move on with confidence that my code is as clean as I can make it. I hope this brief overview helps clear away some of the mystery around what a refactor looks like in real life.&lt;/p&gt;

</description>
      <category>react</category>
      <category>refactor</category>
      <category>javascript</category>
    </item>
    <item>
      <title>A few ways I use Bash</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Thu, 17 Oct 2019 16:58:33 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/a-few-ways-i-use-bash-2mhh</link>
      <guid>https://dev.to/jenniferlynparsons/a-few-ways-i-use-bash-2mhh</guid>
      <description>&lt;p&gt;Bash is an underrated power tool in most developers toolbox. Here's a few ways to make it work for you.&lt;/p&gt;

&lt;p&gt;I've got a short, simple Bash profile on each of my machines that helps me get my job done. It's low-friction with easy to remember commands set up that not only save me a few keystrokes, but make things a little more fun, too. Today, I'm going to go over a few of them and talk a bit about why I set them up and ways you can customize them for your own use.&lt;/p&gt;

&lt;p&gt;Before I start breaking my setup down for you, if you've never used a Bash command before, I'll direct you to a few useful links to help get you started:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=v-F3YLd6oMw"&gt;Shell Scripting Crash Course - Beginner Level&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.bash.academy/"&gt;The Bash Academy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.theodinproject.com/courses/web-development-101/lessons/command-line-basics-web-development-101"&gt;Command Line Basics&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While writing Bash in the command line is useful on its own, I find it most powerful when I set up commands in a &lt;code&gt;.bash_profile&lt;/code&gt; file. This is where the magic starts!&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables &amp;amp; Basic Aliases
&lt;/h2&gt;

&lt;p&gt;Okay! Now that you have a bit more knowledge about Bash in general, I'll show you my favorite uses for the language: variables and creating aliases!&lt;/p&gt;

&lt;p&gt;In Bash, variables can be used to point to various folders and make the functions we write more &lt;a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself"&gt;DRY&lt;/a&gt;. They're defined without a &lt;code&gt;$&lt;/code&gt; at assignment, but are called with &lt;code&gt;$&lt;/code&gt; when used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mainrepo='main-repo-name'

$ cd $mainrepo
// navigates to "main-repo-name"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Distinct from variables, but with similar usage, are aliases. They can contain commands as well as paths, variables, and function calls. They can also contain other aliases!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias dev="npm run dev"

$ dev
// runs the "npm run dev" command
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Building Aliases
&lt;/h2&gt;

&lt;p&gt;I use aliases to build up a set of tools that make navigating folders, opening applications, and launching local environments much easier for myself.&lt;/p&gt;

&lt;p&gt;I'll outline an example here to show you how this might work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias cuppa="code $HOME/Projects/cuppa"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will create an alias called "cuppa" (the name of my current side project) and when I run that command, it will open the project folder in VS Code for me. Note that &lt;code&gt;$HOME&lt;/code&gt; variable? That comes for free on Unix-based environments and points to the current user's home folder.&lt;/p&gt;

&lt;p&gt;Okay, so that opens my project files into my text editor, but what about the terminal itself? I have an alias for that as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias current="cd; cd Projects/cuppa"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here the alias called "current" is set to do two things (it's starting to get magical now!). First it will &lt;code&gt;cd&lt;/code&gt; into the home folder to make sure the shell doesn't get confused on where to look for the folder. Then it will navigate via &lt;code&gt;cd Projects/cuppa&lt;/code&gt; so that folder is currently active.&lt;/p&gt;

&lt;p&gt;Once I'm inside that folder, I've got aliases that help me run my npm scripts more efficiently:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias coverage="npm run coverage"
alias dev="npm run dev"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here I'm using the alias &lt;code&gt;coverage&lt;/code&gt; to enable me to run my Jest tests with coverage reports. In this case we've got some alias inception going on because &lt;code&gt;coverage&lt;/code&gt; is a script in my package.json that is a shortcut for &lt;code&gt;jest --coverage --colors&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Similarly, &lt;code&gt;npm run dev&lt;/code&gt; is a shortcut for &lt;code&gt;concurrently \"npm run server\" \"npm run client\"&lt;/code&gt; and inside that, even &lt;code&gt;server&lt;/code&gt; and &lt;code&gt;client&lt;/code&gt; are shortcuts!&lt;/p&gt;

&lt;p&gt;Any of these can be set up as Bash aliases as well. To give an example of what we're saving in commands and keystrokes, here's what I would have to type in the command line to get my Cuppa app up and running without aliases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ code $HOME/Projects/cuppa
$ cd
$ cd Projects/cuppa
$ concurrently
$ nodemon server/server.js
$ webpack-dev-server --config ./webpack.config.js --mode development
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With my aliases setup, this is what I type instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cuppa
$ current
$ start
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Next Level Aliases
&lt;/h2&gt;

&lt;p&gt;Hopefully you've seen some of the power of Bash and aliases. But when I look at that shortcut setup, I start wondering if I can make this even easier. Well, we can string aliases into a new alias! It looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias goodmorning="cuppa; current; start;"

$ goodmorning
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now when I type the command &lt;code&gt;goodmorning&lt;/code&gt; I tell my shell to open my project in VS Code, navigate into the project folder, and start the local server up! With just a single word (you can even make an alias a single letter!) I'm up and running and ready to start working. MAGIC!&lt;/p&gt;

&lt;p&gt;Note the &lt;code&gt;;&lt;/code&gt; between each command. That's essential so the shell doesn't try to run the entire alias as a single command. The semi-colon takes the place of the enter key in this case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tips and More Examples
&lt;/h2&gt;

&lt;p&gt;I have a few tips for creating a Bash profile:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't forget to reload your profile whenever you make changes! If you're wondering why an alias isn't working, it's possibly because the shell needs to reload to reflect your changes. As you might expect by now, I've created an alias to help me with this!
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias reload=". ~/.bash_profile"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Keep your alias names simple and easy to remember. Having an arcane system that you don't remember off the top of your head will make this considerably less useful.&lt;/li&gt;
&lt;li&gt;Don't just limit yourself to folder navigation. You can use aliases to set settings, start servers, and do other powerful things.&lt;/li&gt;
&lt;li&gt;You can update the aliases as often as you'd like. I have a &lt;code&gt;current&lt;/code&gt; alias for my most often opened current project, but when that changes, I'll update my profile to reflect the new project. Variables are a great way to hold this bit of information to be used across aliases.&lt;/li&gt;
&lt;li&gt;Most importantly, figure out what's going to be most useful for you. There's no reason to copy any of my examples if your workflow is different from mine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are a few more examples of what's possible with your Bash profile:&lt;/p&gt;

&lt;h3&gt;
  
  
  Start a simple server in the folder you &lt;code&gt;cd&lt;/code&gt; into, just pass in a port
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias simple="python -m SimpleHTTPServer"

$ simple 8000
// This opens a local web server at port 8000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  This shortens the bash command line status, and includes the current directory name and git status
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias short='export PS1="\\$\[\e[36m\]\W\[\e[m\]\[\e[35m\]\`parse_git_branch\`\[\e[m\] "'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that there's a call to a function &lt;code&gt;parse_git_branch&lt;/code&gt;. While I didn't go into functions in this article, they're a powerful way of making your Bash profile even more useful!&lt;/p&gt;

&lt;h3&gt;
  
  
  This can be run to open your bash file for easy editing. Change "code" to your choice of IDE (code opens VS Code)
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias open="code $HOME/.bash_profile"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  This echoes the message out to the terminal to confirm that the bash profile has been loaded.
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo '************************************************'
echo '************* Bash Profile Sourced *************'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;While this isn't an alias (the &lt;code&gt;echo&lt;/code&gt; command only writes its value to the command line) it's useful in confirming that changes made to the profile have been loaded.&lt;/p&gt;

&lt;h3&gt;
  
  
  Show/Hide hidden folders
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias showhidden="defaults write com.apple.finder AppleShowAllFiles YES"
alias hidehidden="defaults write com.apple.finder AppleShowAllFiles FALSE"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;On the Mac, option + click on the finder icon and relaunch finder for this to take effect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Notes
&lt;/h2&gt;

&lt;p&gt;I hope you can see the possibilities here are limitless. I personally think Bash automation is one of the most underrated skills in software development and something we can use to make our dev time more efficient so we can get on with the fun stuff.&lt;/p&gt;

&lt;p&gt;I've only showed you a few of the ways I personally use my Bash profile to make my day run more smoothly. If you'd like to see more, you can check out &lt;a href="https://github.com/jenniferlynparsons/evolving-resources/tree/master/bash"&gt;evolvingbash&lt;/a&gt;, my open-sourced bash profile.&lt;/p&gt;

&lt;p&gt;Now go forth and make use of that magical terminal!&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.bashoneliners.com/"&gt;bashoneliners.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ezprompt.net/"&gt;Easy Bash PS1 Generator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://invent.life/project/bash-infinity-framework"&gt;Bash Infinity Framework&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://natelandau.com/my-mac-osx-bash_profile/"&gt;Nathaniel Landau's Bash Profile&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bash</category>
      <category>productivity</category>
    </item>
    <item>
      <title>A guide to basic CSS resources</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Wed, 16 Oct 2019 15:00:46 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/a-guide-to-basic-css-resources-13nm</link>
      <guid>https://dev.to/jenniferlynparsons/a-guide-to-basic-css-resources-13nm</guid>
      <description>&lt;p&gt;CSS is a broad topic as the styling language is more complex than it appears at the surface. The more modern additions of grid, flexbox, and various animation tools (not to mention preprocessors!) has made the topic difficult to sum up in a guide such as this. That said, for this guide I have selected the courses, articles, and other resources that I've found most helpful or return to on a regular basis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Introductions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS"&gt;MDN: CSS: Cascading Style Sheets&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The MDN guide is the defacto standards documentation for web developers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.theodinproject.com/courses/html5-and-css3#css"&gt;The Odin Project Introduction to CSS&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"Here we'll cover each of the foundational CSS concepts in greater depth than you probably have before."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.cssbasics.com/"&gt;CSS Basics&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"You've heard the buzz about the separation of style from content, but you are stuck in the world of nested tables and deprecated markup. If so, you have come to the right place!"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=1PnVor36_40"&gt;Learn CSS in 20 Minutes&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"In this video we will cover everything you need to know to get up and running with CSS in only 20 minutes."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=yfoY53QXEnI"&gt;CSS Crash Course For Absolute Beginners&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"In this video I will cram as much as possible about CSS. We will be looking at styles, selectors, declarations, etc."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.smashingmagazine.com/2019/01/how-to-learn-css/"&gt;How To Learn CSS&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"You don't need to commit to memorizing every CSS Property and Value, as there are good places to look them up. There are some fundamental things, however, which will make CSS much easier for you to use."&lt;/p&gt;

&lt;h2&gt;
  
  
  Flexbox
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://hacks.mozilla.org/2018/01/new-flexbox-guides-on-mdn/"&gt;New flexbox guides on MDN&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;A list of the MDN guides and a useful syllabus for learning flexbox.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://flexbox.io/"&gt;What the Flexbox?!&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"A simple, free 20 video course that will help you master CSS Flexbox!"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=JJSoEo8JSnc"&gt;Flexbox CSS In 20 Minutes&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"In this quick video we will go over the CSS Flexbox model."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://egghead.io/courses/flexbox-fundamentals"&gt;Flexbox Fundamentals&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Another brief course on flexbox&lt;/p&gt;

&lt;p&gt;&lt;a href="https://flexboxfroggy.com/"&gt;Flexbox Froggy&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"Welcome to Flexbox Froggy, a game where you help Froggy and friends by writing CSS code!"&lt;/p&gt;

&lt;h2&gt;
  
  
  Grid
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout"&gt;MDN: CSS Grid Layout&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;A series of guides and references for CSS Grid&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cssgrid.io/"&gt;CSS GRID.&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"Learn CSS Grid with Wes Bos in 25 pretty good videos"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=jV8B24rSN5o"&gt;CSS Grid Layout Crash Course&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"In this video we will look at the new CSS Grid layout and how to create grid based layouts and alignments."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/learn-css-grid-in-5-minutes-f582e87b1228/"&gt;Learn CSS Grid in 5 minutes - A tutorial for beginners&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"Grid layouts are fundamental to the design of websites, and the CSS Grid module is the most powerful and easiest tool for creating it."&lt;/p&gt;

&lt;h2&gt;
  
  
  Animation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animations"&gt;MDN: Using CSS animations&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The MDN resource guide on animations&lt;/p&gt;

&lt;p&gt;&lt;a href="https://css-animations.io/"&gt;Hello, animation!&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"Welcome to our CSS Animation course curious CSS explorer!"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cssanimation.rocks/"&gt;CSS Animation&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"CSS animation articles, tips and tutorials."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=zHUpx90NerM"&gt;CSS3 Animation &amp;amp; Transitions Crash Course&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"This is a beginner friendly crash course on CSS animation using keyframes as well as CSS transitions."&lt;/p&gt;

&lt;h2&gt;
  
  
  Organization
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://css-tricks.com/methods-organize-css/"&gt;Methods to Organize CSS&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"Developer Ben Frain once remarked that it's easy to write CSS code, but it is hard to scale and support it. This article describes the set of solutions out there to deal with this problem."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/yuanchuan/CSS-at"&gt;CSS At __&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"A collection of styleguides or approach to CSS at different companies"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.sitepoint.com/css-architecture-css-file-organization/"&gt;CSS Architecture: CSS File Organization&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"Part of a good CSS architecture is file organization."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.shayhowe.com/advanced-html-css/performance-organization/"&gt;Performance &amp;amp; Organization&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"Having the ability to write HTML and CSS with a solid understanding is a great expertise to have."&lt;/p&gt;

&lt;h2&gt;
  
  
  Preprocessors
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/CSS_preprocessor"&gt;CSS preprocessor&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The MDN glossary definition, with a few links to the most popular preprocessors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://htmlmag.com/article/an-introduction-to-css-preprocessors-sass-less-stylus"&gt;An Introduction to CSS Pre-Processors: SASS, LESS and Stylus&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"CSS Pre-processors are in our development life for years. In their first implementations, they had few features. But nowadays, they are the key ingredients and must have tools for CSS development."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.shayhowe.com/advanced-html-css/preprocessors/#scss-sass"&gt;SCSS &amp;amp; Sass&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;A thorough overview of SCSS and Sass, arguably the most widespread preprocessor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://guide.freecodecamp.org/css/css-preprocessors/"&gt;CSS Preprocessors&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The Free Code Camp guide to preprocessors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://css-tricks.com"&gt;CSS Tricks&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;This is probably the most premiere source for all things CSS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/AllThingsSmitty/css-protips"&gt;CSS Protips&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"A collection of tips to help take your CSS skills pro"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cssreference.io/"&gt;CSS Reference&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"A free visual guide to CSS"&lt;/p&gt;

&lt;p&gt;&lt;a href="http://batificity.com/"&gt;Batificity&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"Not the css specificity guide you deserve, but the one you need right now."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://every-layout.dev/"&gt;Relearn CSS layout&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;"If you find yourself wrestling with CSS layout, it's likely you're making decisions for browsers they should be making themselves. Through a series of simple, composable layouts, Every Layout will teach you how to better harness the built-in algorithms that power browsers and CSS."&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
    </item>
    <item>
      <title>An absolute beginners guide to web development resources</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Tue, 30 Jul 2019 16:27:45 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/an-absolute-beginners-guide-to-web-development-resources-30m7</link>
      <guid>https://dev.to/jenniferlynparsons/an-absolute-beginners-guide-to-web-development-resources-30m7</guid>
      <description>&lt;p&gt;If you've never coded before but are interested in learning some of the basics, I have a few resources for you. I've provided a small number of introductory links as well as a few more thorough course options. I did my best to choose just enough options to not overwhelm you, but still provide choices that will hopefully fit your learning style.&lt;/p&gt;

&lt;p&gt;Coding is a challenging, interesting skill that can take years to gain mastery. HOWEVER! The basics can be learned and used to enrich your life and help you understand how to use the tools and technology of our modern world. Just like learning how to change the oil and keep the tires filled on a car helps you use it better, learning just a bit about how code and the internet works helps you be a more knowledgeable citizen of the good ol' World Wide Web.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Introductions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.khanacademy.org/computing/computer-science/how-computers-work2"&gt;How Computers Work - Khan Academy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"Learn everything from what makes something a computer in the first place, how computers use electrical circuits to store and process information, and the ways hardware and software work together."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.khanacademy.org/computing/computer-science/internet-intro"&gt;Internet 101 - Khan Academy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"In six short, introductory videos, you’ll get an inside look into foundational concepts of everything from wires to websites"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.theodinproject.com/courses/web-development-101/lessons/how-does-the-web-work"&gt;How Does the Web Work? - The Odin Project&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"These concepts provide a more holistic understanding of the ecosystem in which you will be working and will enable you to talk intelligently with other developers about your work."&lt;/p&gt;

&lt;h2&gt;
  
  
  Beginner Coding Courses
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/"&gt;Free Code Camp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"You'll learn to code by completing coding challenges and building projects. You'll also earn verified certifications along the way. We also encourage you to join a study group in your city so you can code in-person with other people."&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is my personal favorite and yes it really is free.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.theodinproject.com"&gt;The Odin Project&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"Our full stack curriculum is free and supported by a passionate open source community."&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This curriculum builds on other resources around the web, curating a thorough code education.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.traversymedia.com/"&gt;Traversy Media&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An excellent source of courses and youtube tutorials that include crash courses to get a brief overview of various coding topics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.codecademy.com"&gt;Codecademy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Codecademy has a mix of free and paid courses and is a viable alternative to Free Code Camp if that doesn't fit your style.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.learnenough.com/"&gt;Learn Enough to be Dangerous&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"Learn Enough is based on the idea that you don’t have to learn everything to get started—you just have to learn enough to be dangerous."&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I don't get any kickback for these paid courses, but can recommend them for beginners.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What I've learned about testing React applications</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Tue, 30 Jul 2019 12:47:57 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/what-i-ve-learned-about-testing-react-applications-5bmn</link>
      <guid>https://dev.to/jenniferlynparsons/what-i-ve-learned-about-testing-react-applications-5bmn</guid>
      <description>&lt;p&gt;&lt;em&gt;TL;DR Testing on the front end is one of the most personalized aspects of development, with a variety of shifting tools and opinions, particularly for the React ecosystem. Be patient with yourself when you're learning how to test. In my experience, it's one of the more challenging things to teach yourself.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I spent a lot of time recently digging into React testing and came away with more knowledge than when I started, though I still have some lingering confusion. I did, however, develop a system that feels workable to me and makes my tests make sense with how I work. Currently, it seems that's the best we can ask for as React testing is evolving at a rapid pace.&lt;/p&gt;

&lt;p&gt;While it can be frustrating that best practices for testing React are in such flux, I'm hoping this article will shed a little light on the various options and be a step toward some kind of consensus.&lt;/p&gt;

&lt;h2&gt;
  
  
  General thoughts
&lt;/h2&gt;

&lt;p&gt;Before I dive into the React-specific information, I thought I would share a few general thoughts about testing. Words of wisdom, if you will, based on my experiences. They serve me as reminders of why testing is important and the reality of what writing tests is really like.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Yes, you're basically writing a stripped down version of the logic of your app all over again in a different framework.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are some loose best practices that have been inherited from the backend, but folks seem to be even more splintered on how testing should be handled than they are on which framework you should use. What works is something you'll have to decide with your team.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Writing tests requires thinking very differently about your app than you usually do, and will have you rethinking how you're handling data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Coverage is an imperfect gauge for quality. If you have not written "unhappy path" code (else statements, catch blocks, etc.) your coverage will be inaccurate. You can't test code you haven't written.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Writing tests does indeed increase the amount of time, code, and effort it takes to write an app. That's not an illusion and it's something to be accepted as part of the process because...&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It saves an unseen amount of time and effort you would have put into debugging, especially during refactors. You won't know how much you've saved because you won't be doing that work. This is easy to forget.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tools
&lt;/h2&gt;

&lt;p&gt;When it comes to testing React applications, there are choices depending on how you approach your testing. Do you want to focus on integration tests? Unit tests? Or do you prefer functional tests? And yes, those terms have different definitions depending on who you ask. Learning about these options was a good reminder that React is technically a &lt;em&gt;library&lt;/em&gt; and not a &lt;em&gt;framework&lt;/em&gt;. That means there is a lot of customization possible and that is abundantly clear with testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic testing&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ReactTestUtils: React's own built-in testing utility, which is no longer recommended even by the React team.&lt;/li&gt;
&lt;li&gt;Jest: the defacto standard library for React testing, built by Facebook specifically to test React applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Built on Jest&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React Testing Library: the currently recommended component testing library, it tests components the same way your users use them.&lt;/li&gt;
&lt;li&gt;Enzyme: a widely used testing library and competitor to RTL. It allows you to traverse and manipulate your components' output.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Integration&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cypress: end-to-end testing with time travel, snapshots, and a browser-based interface.&lt;/li&gt;
&lt;li&gt;Puppeteer: end-to-end testing that runs headless Chrome and allows you to write tests that interact with the browser without running it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Alternatives&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mocha/Chai/Karma: since React is really just JavaScript, these stable, venerable testing tools can be used as well.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A few other options can be found in the &lt;a href="https://reactjs.org/community/testing.html"&gt;React docs' Community section&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That covers most of the options for basic testing. There are also numerous supplemental tools that can be used, depending on your application. For example, &lt;code&gt;redux-mock-store&lt;/code&gt; is often used to mock the redux store and &lt;code&gt;moxios&lt;/code&gt; can be used to mock &lt;code&gt;axios&lt;/code&gt; for API testing, though there are other options for testing both of these tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  Documentation &amp;amp; Notes
&lt;/h2&gt;

&lt;p&gt;I found the documentation for most of these tools to be very dense, referring to concepts that are fairly complex without significant prior knowledge. When I tried applying the lessons from the basic tutorials I found, I was quickly frustrated that they did not align with the more complex code base I was trying to test. By "more complicated" I mean that I was using Redux and React Router on top of React, so in the real world, not actually all that complicated.&lt;/p&gt;

&lt;p&gt;There were a few important concepts that were not clearly explained in the various documentations I read. Here's what I've gleaned from the docs and learned from others who are also trying to figure this all out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Individual &lt;em&gt;files&lt;/em&gt; are run in parallel (unless you enable the runInBand option). So it is not safe for multiple test files to share a mutable data store. All describe and test blocks within a file always run in serial, in declaration order. This is important to note if you are mutating data between tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React Testing Library does not rerender the component when props change if you are working outside the redux store, even if you try to feed in new props. Anything to do with a lifecycle method other than &lt;code&gt;componentDidMount&lt;/code&gt; will not be run. You can manually pass in updated props and manually rerender the component, but that's not the same as testing the result of a redux call. For that kind of testing, Cypress may be a better choice.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you have any links from React Router or want to test that redirects work on your component, RTL's standard &lt;code&gt;render&lt;/code&gt; function will not be enough. You must use the &lt;code&gt;renderWithRouter&lt;/code&gt; function found here: &lt;a href="https://testing-library.com/docs/example-react-router"&gt;React Router · Testing Library&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Named arrow functions in class properties aren't in the prototype so unit testing them is challenging. A fat-arrow assignment in a class in JS is not a class method; it's a class property holding a reference to a function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Snapshots, despite being presented as a first step in most testing libraries' documentation, are not as useful as they seem at first glance and are generally avoided by many developers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mocking can be challenging without a full understanding of how it works and what can be expected from it. I've written a separate article &lt;a href="https://dev.to/jenniferlynparsons/a-bit-about-jest-mocks-2o7k"&gt;specifically on mocking&lt;/a&gt; covering some of the basics, though it's important to note that Promises add an additional layer of complexity.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With all that said, documentation is still a solid place to start when learning testing. Reading it through thoroughly and then following up with research into any new terminology will enable you to ask better questions.&lt;/p&gt;

&lt;p&gt;I found it helpful to search for any errors that come up as well. Discovering what was a problem with my tests vs. my code vs. a configuration issue was challenging, but with each issue I refined my knowledge of how the pieces fit together.&lt;/p&gt;

&lt;p&gt;I also highly recommend joining the communities of the various testing libraries and reading through the issues in their github repos. Many questions I had were answered in these places more efficiently than in the documentation, especially when it came to the complexity added by using Redux, thunk and other non-native React tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  My own system
&lt;/h2&gt;

&lt;p&gt;Currently, I've chosen to use the following setup on my side projects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Jest&lt;/li&gt;
&lt;li&gt;React Testing Library&lt;/li&gt;
&lt;li&gt;redux-mock-store&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I also have a "test" folder where all of my test data is stored in fixtures along with a few testing utilities. For reference, the test utilities are &lt;a href="https://gist.github.com/jenniferlynparsons/fe79f5c1a7a00da44c7f53fff99c1cd7"&gt;stored in a gist&lt;/a&gt;. The fixtures and other setup details can be &lt;a href="https://github.com/jenniferlynparsons/cuppa-webpack"&gt;viewed in one of my side projects&lt;/a&gt;. (I have a boilerplate in the works that will include this style of testing)&lt;/p&gt;

&lt;h3&gt;
  
  
  Guidelines
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Fixtures and utilities are stored in the root level &lt;code&gt;test&lt;/code&gt; folder.&lt;/li&gt;
&lt;li&gt;Use fixtures for data unless it is a small amount (less than line) of single-use data.&lt;/li&gt;
&lt;li&gt;Prefer reusable test data and utilities. Keep tests DRY, too!&lt;/li&gt;
&lt;li&gt;Tests exist alongside the elements they are testing. Each component folder should contain a &lt;code&gt;__tests__&lt;/code&gt; folder and tests should be named to match their component.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tests
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Structure of a test file
&lt;/h4&gt;

&lt;p&gt;Not all test suites require all of the structure outline below, but this is the preferred order for each of the files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Imports

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;li&gt;React Testing Library&lt;/li&gt;
&lt;li&gt;Other required packages &amp;amp; libraries&lt;/li&gt;
&lt;li&gt;testUtils&lt;/li&gt;
&lt;li&gt;routerTestUtils&lt;/li&gt;
&lt;li&gt;data fixtures&lt;/li&gt;
&lt;li&gt;connected container component&lt;/li&gt;
&lt;li&gt;unconnected container component&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Constants&lt;/li&gt;
&lt;li&gt;Mock Functions&lt;/li&gt;
&lt;li&gt;Variables for beforeEach&lt;/li&gt;
&lt;li&gt;beforeEach/afterEach setup/teardown functions&lt;/li&gt;
&lt;li&gt;Describe block

&lt;ul&gt;
&lt;li&gt;test block&lt;/li&gt;
&lt;li&gt;variables (including spies)&lt;/li&gt;
&lt;li&gt;store.dispatch&lt;/li&gt;
&lt;li&gt;fireEvent&lt;/li&gt;
&lt;li&gt;expect&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Notes on my testing style
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Data fixtures are not aliased to variables unless needed for mocking purposes.&lt;/li&gt;
&lt;li&gt;The first describe block for any test suite is the basic render of the component with the connected store or a test that the function or object being tests exists.&lt;/li&gt;
&lt;li&gt;The second describe block tests basic interactions.&lt;/li&gt;
&lt;li&gt;All other tests come after the first two.&lt;/li&gt;
&lt;li&gt;Multiple expects are acceptable in a single test as long as they are all related to the same functionality and relevant to the test.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;I hope some of this information is helpful to those also interested in developing a solid testing strategy. Perhaps one day we'll have more standardized approaches for testing on the front end, but until then, I encourage you all to share your own findings and experiences working with tests.&lt;/p&gt;

</description>
      <category>react</category>
      <category>testing</category>
    </item>
    <item>
      <title>Xpath for you and me</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Mon, 29 Jul 2019 13:38:31 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/xpath-for-you-and-me-15mi</link>
      <guid>https://dev.to/jenniferlynparsons/xpath-for-you-and-me-15mi</guid>
      <description>&lt;p&gt;I learned XPath a few years ago and always found myself frustrated with the documentation for it. There were a few basic concepts that seemed to trip me up on it as I learned it. My hope with this brief article is that I can make it a little easier for the next person who needs to learn this small but mighty tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is XPath?
&lt;/h2&gt;

&lt;p&gt;XPath stands for XML Path Language&lt;/p&gt;

&lt;p&gt;XPath is designed to be used to point to parts of an XML document. We use it to do pattern matching between DOM nodes. It is used in XSLT, Selenium and other areas where DOM navigation is useful.&lt;/p&gt;

&lt;p&gt;When looking at the syntax of an xpath query, view it as if the DOM is a file hierarchy that we are navigating, similar to URL paths. It intuitively makes a bit more sense that way. Each parent element is a "folder" that can contain other folders (child elements).&lt;/p&gt;

&lt;p&gt;The general syntax is similar to regex and CSS selectors as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  XPath query structure
&lt;/h2&gt;

&lt;p&gt;XPath queries are made up of four parts. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The prefix determines the starting point of the query.&lt;/li&gt;
&lt;li&gt;The axis refers to the relationship of the context node.&lt;/li&gt;
&lt;li&gt;The step is also the context node, the identifier of the element we’re referencing.&lt;/li&gt;
&lt;li&gt;The predicate makes the step more specific&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The less specific XPath queries are the more expensive they become, performance-wise. Similar to CSS selectors, there is a balance between specificity vs. flexibility and performance.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tr&gt;&lt;td colspan="4"&gt;Parts of an XPath query&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;//&lt;/td&gt;
&lt;td&gt;ul&lt;/td&gt;
&lt;td&gt;/&lt;/td&gt;
&lt;td&gt;a[&lt;a class="comment-mentioned-user" href="https://dev.to/id"&gt;@id&lt;/a&gt;
='link']&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Prefix&lt;/td&gt;
&lt;td&gt;Step&lt;/td&gt;
&lt;td&gt;Axis&lt;/td&gt;
&lt;td&gt;Step with predicate&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Axis selector examples
&lt;/h3&gt;

&lt;p&gt;Axis selectors allow us to "drill down" into the structure we're processing to access the node we're looking for.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Axis selector&lt;/th&gt;
&lt;th&gt;Examples&lt;/th&gt;
&lt;th&gt;Context&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/section/div//a&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Anywhere in the document when prefix (This will set the context to any descendent element)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;./&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;./a&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Child relative to the current node&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/html/body/div&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Start at the root (This will also select the context to any child element)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;.&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Self node&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;..&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;..&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Parent node&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;./*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Any node&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Navigation
&lt;/h2&gt;

&lt;p&gt;XPath also allows you to navigate up and down the hierarchy of the DOM, just like with folder navigation. &lt;/p&gt;

&lt;p&gt;Selectors can be chained and can include some limited logic. They are based on various pattern matching criteria, similar to regex. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;relationship (child, sibling, preceding, self)&lt;/li&gt;
&lt;li&gt;attributes (id, class name, href)&lt;/li&gt;
&lt;li&gt;order (first, last)&lt;/li&gt;
&lt;li&gt;content (contains string “xyz”)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Selector examples
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Context&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//ul/li/a&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Relationship selector, matches a direct child relationship&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//input[@type="submit"]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Attribute selector&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//ul/li[2]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Order selector, selects second child &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt;. Note: this is not zero indexed.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//button[contains(text(),"Go")]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains text, in this case matching a substring&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//a[@name or @href]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Or logic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//ul/li/../../.&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Selects the parent of the &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; (for example, a &lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; &amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; structure)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//h1[not(@id)]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not selector. This example selects any &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; without an id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;./a[1][@href='/']&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;An example of chaining. Here we’re selecting the first &lt;code&gt;&amp;lt;a href=”/”&amp;gt;&lt;/code&gt; within the current context&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A note about &lt;code&gt;contains()&lt;/code&gt;. This selector is rather loose and will select any string that contains the string parameter that is passed to it. This can cause unexpected results. In the example above, any button with the string &lt;code&gt;Go&lt;/code&gt; in it will be selected, in this case &lt;code&gt;Go Home&lt;/code&gt; and &lt;code&gt;Go to Next Page&lt;/code&gt; would both be selected. Combining the various selectors can produce the results you seek.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;MDN&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/XPath"&gt;https://developer.mozilla.org/en-US/docs/Web/XPath&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Devhints.io&lt;br&gt;
&lt;a href="https://devhints.io/xpath"&gt;https://devhints.io/xpath&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scrapy documentation&lt;br&gt;
&lt;a href="https://doc.scrapy.org/en/xpath-tutorial/topics/xpath-tutorial.html"&gt;https://doc.scrapy.org/en/xpath-tutorial/topics/xpath-tutorial.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>xpath</category>
    </item>
    <item>
      <title>A bit about Jest mocks</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Fri, 07 Jun 2019 20:28:32 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/a-bit-about-jest-mocks-2o7k</link>
      <guid>https://dev.to/jenniferlynparsons/a-bit-about-jest-mocks-2o7k</guid>
      <description>&lt;p&gt;I've been learning Jest and applying it to a side project built in React. As I run across various challenges I've cobbled together some things that I thought might be helpful for others new to testing. A few bits of information here were a challenge to locate. I came by them via my network and some asking around and trial and error. This post is my way of paying that forward.&lt;/p&gt;

&lt;p&gt;My plan is to give a very brief overview of mocks in general, a few examples from my real life codebase, and provide a few resources for further information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mocks in general
&lt;/h2&gt;

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

&lt;p&gt;"Mock functions make it easy to test the links between code by erasing the actual implementation of a function, capturing calls to the function (and the parameters passed in those calls), capturing instances of constructor functions when instantiated with new, and allowing test-time configuration of return values."&lt;/p&gt;

&lt;p&gt;That's a mouthful. What it basically means is that a mock replaces a function call within the test with a fake version. That means you grab the name of a function and replace it with a different implementation. &lt;/p&gt;

&lt;p&gt;Does this mean you're just rewriting that function inside the test? I can see where you might think that. However, with this mock version of the function, you only need the bare minimum of code. It can return a basic value and should not include any logic. You aren't testing how this function works after all, instead you're testing the function that calls this function. &lt;/p&gt;

&lt;h2&gt;
  
  
  Mocks in Jest
&lt;/h2&gt;

&lt;p&gt;Jest has a couple of built-in methods for creating mock functions. The most basic is &lt;code&gt;jest.fn()&lt;/code&gt;, but I haven't found that useful on its own so far. In my codebase, which is a MERN stack project using Redux, I've found that method most useful inside other mocks. Your mileage may vary, as they say.&lt;/p&gt;

&lt;p&gt;I've used a couple of Jest mocks in my own tests. I'm going to give the examples here and walk through them as best I can.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;jest.mock()&lt;/code&gt; function call takes two arguments. The first is a string that contains the path to the module that contains the function being called (or the name of the Node module). The second is an optional function that is used in place of the original function.&lt;/p&gt;

&lt;p&gt;Mocks in Jest also have a special set of assertions. Since they are not intended to provide the same functionality as the original function calls, mocks are generally used only to assert that a function has been called. We can determine how many times it's been called or what arguments are used to call it, but that's about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;The code for the tests and the code being tested (in stripped down versions) can all be found in &lt;a href="https://gist.github.com/jenniferlynparsons/da7dc004bcf868d15ab7f1f545f8977e#file-authactions-test-js-L16"&gt;this gist&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mocking a module function
&lt;/h3&gt;

&lt;p&gt;This is a mock I have set up to provide a faked function call. The pathname is given and then the result of that call is faked with &lt;code&gt;() =&amp;gt; jest.fn()&lt;/code&gt;, a function that returns a function. This reflects the structure of the &lt;code&gt;setAuthToken&lt;/code&gt; function and for the test, that's all we need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jest.mock("../../utils/setAuthToken", () =&amp;gt; jest.fn());
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That mock is used in the test below soley to ensure that inside of my &lt;code&gt;loginAction()&lt;/code&gt; action creator, the &lt;code&gt;setAuthToken&lt;/code&gt; function has been called. Elsewhere, I've tested that &lt;code&gt;setAuthToken&lt;/code&gt; returns the expected response, but this is a unit test, so I'm only looking to ensure the call is made.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test("it sets the JWT token to the response from the POST", async () =&amp;gt; {
  await store.dispatch(loginAction(mockLoginData));
  expect(setAuthToken).toHaveBeenCalledWith(mockResponse.token);
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Mocking a Node module
&lt;/h3&gt;

&lt;p&gt;This mock sets up the &lt;code&gt;jwt-decode&lt;/code&gt; node module fake so that when it is used in the next test, I can be sure that I once again am getting a call out to the correct function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jest.mock("jwt-decode");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here is the test where that is used. Note that I'm only looking to ensure that &lt;code&gt;.toHaveBeenCalledWith&lt;/code&gt; is a &lt;code&gt;true&lt;/code&gt; assertion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test("it decodes the token with jwt_decode", async () =&amp;gt; {
  await store.dispatch(loginAction(mockLoginData));
  expect(jwt_decode).toHaveBeenCalledWith(mockResponse.token);
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Mocking an API call
&lt;/h2&gt;

&lt;p&gt;This mock is being used to fake an API call, in this case, a &lt;code&gt;post&lt;/code&gt; that returns a Promise that is resolved with some fake data. Note the function inside it does a bit more than the first example. Here I'm not just returning an anoymous function wrapped around &lt;code&gt;jest.fn()&lt;/code&gt;. Instead, here I'm returning an object which currently has a &lt;code&gt;post&lt;/code&gt; key and the &lt;code&gt;jest.fn()&lt;/code&gt; function which contains an anonymous function that returns a Promise. Whew!&lt;/p&gt;

&lt;p&gt;Additionally, note that the object it returns can be filled out with the rest of the API methods in comma separated multiple key/value pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jest.mock("../../lib/api", () =&amp;gt; ({
  post: jest.fn(() =&amp;gt; Promise.resolve(mockResponse))
}));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here's what the test that uses that mock looks like. I've faked the &lt;code&gt;API.post&lt;/code&gt; property in the mock. The original version of that function takes two arguments, the path for the call and the data passed to the backend. Here I'm checking that, once again, the function was called with the correct data. In this case, I am also checking that returns a resolved Promise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test("it calls 'post' on the API with the correct path and the user data", () =&amp;gt; {
  store.dispatch(loginAction(mockLoginData));
  expect(API.post).toHaveBeenCalledWith("/users/login", mockLoginData);
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Mocking with a default implementation
&lt;/h3&gt;

&lt;p&gt;This mock combines a few of the mocks above, with an added twist! Here I'm mocking the &lt;code&gt;react-router-dom&lt;/code&gt; node module, just like with the &lt;code&gt;jwt-decode&lt;/code&gt; module. However, I do not want to mock out the entire module. I need to keep &lt;code&gt;Route&lt;/code&gt; intact and only mock &lt;code&gt;Redirect&lt;/code&gt;. To accomplish this, I am using a method similar to the &lt;code&gt;API.post&lt;/code&gt; mock above and returning an object. I'm using the &lt;code&gt;requireActual()&lt;/code&gt; function to grab all of the original, real methods in the module. Inside the &lt;code&gt;return&lt;/code&gt;, I'm first using the spread operator to add those original methods. I'm then overwriting only the &lt;code&gt;Redirect&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;Did you see the little new twist on &lt;code&gt;Redirect&lt;/code&gt;? It's the &lt;code&gt;.mockImplementation()&lt;/code&gt; call. Because unlike the first example where I only needed a function and unlike the API call where I only needed a resolved Promise, in this case I need some kind of returned value. It doesn't have to be a value that matches what would be return in the original code, but I do need to return something. The intent of &lt;code&gt;.mockImplementation()&lt;/code&gt; is to create an actual, if fake, implementation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jest.mock("react-router-dom", () =&amp;gt; {
  const original = jest.requireActual("react-router-dom");
  return {
    ...original,
    Redirect: jest.fn().mockImplementation(() =&amp;gt; null)
  };
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here is the test where that mock is used. In this case I'm making sure that when the user is logged out that they are redirected somewhere else. Because I'm not trying to test &lt;code&gt;react-router-dom&lt;/code&gt; itself, it's enough to know that a redirect has happened without worrying about where to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test("PrivateRoute should redicted to the login page if user is logged out", () =&amp;gt; {
  const store = makeMockStore(loggedOutState);
  let wrapper = mount(
    &amp;lt;MemoryRouter initialEntries={["/dashboard"]} initialIndex={0}&amp;gt;
      &amp;lt;PrivateRoute
        path="/dashboard"
        component={GenericComponent}
        store={store}
      /&amp;gt;
    &amp;lt;/MemoryRouter&amp;gt;
  );
  expect(wrapper.find(Redirect).exists()).toBe(true);
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Spies!
&lt;/h3&gt;

&lt;p&gt;Spies work a little differently, but are still a type of mock. From the official docs: "Creates a mock function similar to &lt;code&gt;jest.fn&lt;/code&gt; but also tracks calls to &lt;code&gt;object[methodName]&lt;/code&gt;. Returns a Jest mock function." What this means is that the function being tracked must exist as a method name on an object. For example, in this case, I'm exporting my methods from &lt;code&gt;authActions.js&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const authActions = { loginAction, registerUser, logoutUser, setCurrentUser };

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



&lt;p&gt;I did this in order to track that the &lt;code&gt;setCurrentUser&lt;/code&gt; method was being called inside the &lt;code&gt;loginAction&lt;/code&gt; method. The reasons this was necessary are beyond the scope of this article, but there's a really great explanation &lt;a href="https://medium.com/@DavideRama/mock-spy-exported-functions-within-a-single-module-in-jest-cdf2b61af642"&gt;here&lt;/a&gt;. The tl;dr is that it has to do with the way Babel compiles JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.spyOn&lt;/code&gt; also calls the &lt;code&gt;spied&lt;/code&gt; method and does not allow you to overwrite the original implementation. &lt;/p&gt;

&lt;p&gt;There is no separate mock for this one, I'm using &lt;code&gt;.spyOn&lt;/code&gt; directly in the test. The function takes two arguments, the object where the function exists and the name of the function. I can then check that when &lt;code&gt;loginAction&lt;/code&gt;, which also lives inside the &lt;code&gt;authActions&lt;/code&gt; object, is called, it calls &lt;code&gt;setCurrentUser&lt;/code&gt; one time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test("it sets the current user action", async () =&amp;gt; {
  let currentUserSpy = jest.spyOn(authActions, "setCurrentUser");
  await store.dispatch(authActions.loginAction(mockLoginData));
  expect(currentUserSpy).toHaveBeenCalledTimes(1);
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Jest mocks, and mocking in general, can be a tricky but they're useful in unit testing because they allow you to test the code you've written without worrying about dependencies. I hope a few of these details clarify some things for you and that by sharing this information someone else might have a little bit easier time learning to write tests.&lt;/p&gt;

&lt;p&gt;Please let me know if you find any errors, I'm looking to learn more!&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://jestjs.io/docs/en/mock-functions"&gt;The Official Jest Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devhints.io/jest"&gt;Jest cheatsheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hackernoon.com/how-do-you-mock-a-react-component-with-jest-unit-test-javascript-tutorial-example-spy-jest-enzyme-6c681f812a00"&gt;[Unit Test] How do you mock a react component with Jest?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@antonybudianto/react-router-testing-with-jest-and-enzyme-17294fefd303"&gt;Testing React Router apps with Jest and Enzyme&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I also want to thank the gang over at &lt;a href="https://wealljs.org/"&gt;WeAllJS&lt;/a&gt; for their invaluable help as I figured this all out.&lt;/p&gt;

</description>
      <category>jest</category>
      <category>mock</category>
      <category>react</category>
      <category>testing</category>
    </item>
    <item>
      <title>Early Returns in JavaScript</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Sun, 29 Jul 2018 18:30:30 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/early-returns-in-javascript-5hfb</link>
      <guid>https://dev.to/jenniferlynparsons/early-returns-in-javascript-5hfb</guid>
      <description>&lt;p&gt;A couple of articles related to how early returns work crossed my path recently, enough to pique my curiosity. Learning about early returns in JS has been not only a challenging technical exploration, but also pretty fun. In researching the concept, I remembered how much I enjoy learning something for it's own sake, not just as a means to an end. Sure, the information I gathered is useful and the technique is something I'll likely employ in the long run, but it was just as valuable enjoying following the trail of breadcrumbs that led to my final conclusion.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an early return?
&lt;/h2&gt;

&lt;p&gt;In short, an early return provides functionality so the result of a conditional statement can be returned as soon as a result is available, rather than wait until the rest of the function is run.&lt;/p&gt;

&lt;p&gt;Surprisingly, I hadn't seen this kind of pattern in JS before, though I'm used to seeing it in Ruby, where it's quite common. I was curious as to why that was. A bit of research showed me that returning only after the rest of the code had run, whether it was needed or not, was a holdover from older imperative programming languages where it was required to return at the end of a function to ensure the code ran in the correct order.&lt;/p&gt;

&lt;p&gt;The only answer I could really find to why I hadn't run into this pattern before is that even now this is not taught nor talked about enough for folks to start using it regularly, dropping the imperative style. A few newer devs have started the conversation and argue quite strongly that it's clearer to read.&lt;/p&gt;

&lt;h2&gt;
  
  
  I still had questions
&lt;/h2&gt;

&lt;p&gt;I was unsure about the readability of this style. I'm so used to reading if/else statements with a variable set at the top of the function that gets returned at the end. Having multiple returns or even multiple if statements (rather than if/else) felt like it would be more challenging to understand at a glance.&lt;/p&gt;

&lt;p&gt;More important than readability, I wondered how performant it was versus the single point/end of function returns. My gut told me it was probably faster because, in theory, less code was being run. In researching this, I found a pre-2012 article hinting it might actually be less performant but didn't find any information after that supporting one style or the other.&lt;/p&gt;

&lt;p&gt;It would be interesting to discover that a single return was faster and if it was, why that was so. I decided to run some benchmarks to see what our winner was.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benchmarking early returns
&lt;/h2&gt;

&lt;p&gt;Here are my benchmark tests: &lt;a href="http://jsbench.github.io/#1fd9788db451f01d4b84e12bba8d706f"&gt;JavaScript benchmark playground&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see when you run the tests, there are only 10s of milliseconds difference in speed between the various options, fairly negligible. While I get slightly different results each time I run the benchmarks, with the old imperitive style comes out on top every time. Not what I was expecting! Generally, it looks like "early return within an if/else" comes in second to "early returns with single statements", though it's pretty much a wash between them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In comparing these examples, I find I prefer a single if/else for readability, regardless of whether it's an early return or single return. While early returns feels less cumbersome than setting up a variable just to have a return value as in single return, knowing that there's a performance hit as well means I'll be likely sticking with the old style. Additionally, having a series of statements inside a function as in the "early returns with single statements" version abstracts the fact that they're consequentially connected to each other and to me, that's less readable.&lt;/p&gt;

&lt;p&gt;All in all I feel like I've gained a deeper grasp on some of JavaScript's inner workings, with the bonus of trying out some benchmarking and learning a bit of programming history as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://wilsonpage.co.uk/return-early/"&gt;Return early - Wilson Page&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://blog.timoxley.com/post/47041269194/avoid-else-return-early"&gt;Probably Wrong - Avoid Else, Return Early&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://softwareengineering.stackexchange.com/questions/18454/should-i-return-from-a-function-early-or-use-an-if-statement"&gt;Should I return from a function early or use an if statement? - Software Engineering Stack Exchange&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://lecterror.com/articles/view/code-formatting-and-readability"&gt;Code formatting and readability - lecterror&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://softwareengineering.stackexchange.com/questions/118703/where-did-the-notion-of-one-return-only-come-from"&gt;Where did the notion of "one return only" come from? - Software Engineering Stack Exchange&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://forum.freecodecamp.org/t/the-return-early-pattern/19364"&gt;The Return Early Pattern - Guide - The freeCodeCamp Forum&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/355670/is-returning-early-from-a-function-more-elegant-than-an-if-statement"&gt;design - Is returning early from a function more elegant than an if statement? - Stack Overflow&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/howtocodejs/stylish-saturday-early-returns-722"&gt;Stylish Saturday: Early Returns&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title> Software as a Tiny House</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Mon, 04 Dec 2017 15:12:17 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/software-as-a-tiny-house-54e</link>
      <guid>https://dev.to/jenniferlynparsons/software-as-a-tiny-house-54e</guid>
      <description>&lt;p&gt;I love the idea of living in a tiny house, something portable and just big enough to fit the essentials. While I don’t know if I would be happy living in one myself, I do love learning about them. &lt;/p&gt;

&lt;p&gt;I was watching some video tours of tiny houses recently and some of the things the folks who lived in and built them had to say resonated with me. However, it didn’t have anything to do with my own living situation. Instead, I found quite a few insights that could be applied to software and website architecture and design. In fact, just the idea that we use those same two terms in both house construction and building software makes me sure the concepts are a natural fit.&lt;/p&gt;

&lt;p&gt;While I’m still pondering these connections, here’s what I gleaned so far from watching those tours:&lt;/p&gt;

&lt;h2&gt;
  
  
  What do the people living there need?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;(don’t build useless spaces, repurpose spaces that are underused)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There are essentials, things that every house and piece of software needs to have to make it useable in general. There are always exceptions, but a kitchen, bath, bed, and living space are all important in a house, even if they all exist in the same room. The same can be said for software. An interface, storage, and functions that process the interactions between the data and the user, are all pretty standard in working software. &lt;/p&gt;

&lt;p&gt;It’s good to ask if a new space or functionality is necessary, and seeking new ways to repurpose the same things in other areas is key to making efficient use of both space and code.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s the most economical way to do it?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;(in energy &amp;amp; resources, not just money)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Tiny houses are often built from recycled materials when possible. It saves cost and is also lower impact on the planet. While any app’s power efficiency (unless you’re Amazon or something) is likely to be small already, looking for ways to make the code run more efficiently is a good practice all around. &lt;/p&gt;

&lt;p&gt;Additionally, when thinking in terms of resources, it’s good to recognize the cost in people hours as well. Solid planning and an understanding of the problem you’re trying to solve will save time and help stem the tide of burnout that’s far too rampant in our industry.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s healthiest for the whole person?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;(make it simple to move through, don’t make things hard to reach, does it breathe)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A tiny house that makes you climb into a loft doesn’t work if you have certain health issues. Large windows might be less energy efficient than small ones, but the benefits gained from the sense of space makes the trade off worth making.&lt;/p&gt;

&lt;p&gt;With software, a strong designer is essential here. If things are difficult for a user to accomplish or are unintuitive or cramped, their experience will be lesser. In some cases, this can mean the loss of return visitors and for some sites and software, those users are critical to success. If your software is meant to be a help to others, than making it difficult to use puts an extra toll on someone who is already compromised.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get to know your space and what you need it to be.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;(requires self-exploration as well as trial and error, make it what it needs to be but no more)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For a tiny house, knowing that there needs to be a priority on the kitchen because the owner is a cook is a vital piece of information. They may ask for a full four-burner stove. Perhaps instead they really only need a two-burner and a portable hot plate, leaving room for a larger sink that will make their living experience more pleasurable in general.&lt;/p&gt;

&lt;p&gt;Knowing who you are building your software for and anticipating their needs is not easy. It takes work and thought and research, but the end result will be a smoother experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Be willing to let the materials guide the building.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;(recycled materials, clever use of non-traditional tools, etc. will change everything)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Tiny houses have limits on them. Size restrictions based on building code or road regulations delineate what is possible to build. That’s where creativity comes into play, maximizing the space in unexpected and clever ways.&lt;/p&gt;

&lt;p&gt;Here an understanding of the tools at your disposal as a developer comes in handy. Rarely does any developer get to choose the libraries or languages they’re working in. Frequently a developer is asked to build something that a language doesn’t necessarily do well. A deep understanding of tools, of architecture, of the language of choice is a great asset in these situations, allowing for a creative use of the resources at hand and providing a satisfying challenge.&lt;/p&gt;

&lt;h2&gt;
  
  
  A small footprint and low power requirements keep it sustainable.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;(will it still work off grid?)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Many tiny houses can work perfectly well off the grid. No power or water hookups needed, they are designed to work well when those options are unavailable. &lt;/p&gt;

&lt;p&gt;Software gets bloated easily. When space is virtually free and libraries are limitless in availability, there’s very little incentive to put any constraints on how the code is actually written. However, with each new layer of complexity from another library and every megabyte of storage used to hold the software, maintenance becomes an issue. Cost, too, can become troublesome, either in the form of server space, energy costs, and environmental impact over time. &lt;/p&gt;

&lt;p&gt;It’s also useful to ask if your software is still useful to someone who has no or limited access to the internet for some reason. What can be done to keep things running at low (or no) latency?&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi use, purpose built functional things solve some problems more efficiently.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;(customization can maximize space and ease of use)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Most things in a tiny house have multiple uses. Very often a couch will also be a storage bench, a table is also a desk. This maximizes both space and utility.&lt;/p&gt;

&lt;p&gt;It’s a useful exercise, at least, to consider the benefits of writing a series of functions to fill a need rather than installing an entire new library of functions that may or may not be used. Testing to make sure that every area of a program is running most efficiently will help reveal code that can be reused or refactored. What functions can be made universal? &lt;/p&gt;

&lt;h2&gt;
  
  
  Ease of use and at hand vs the thought process behind it.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;(is everything within reach and as intuitive as possible?)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A tiny house works best when its owner can move effortlessly through the space and use it as best pleases them. For some, an origami folding cabinet that houses layers of functionality works best. For others, it’s more comfortable to make as few changes to their space as possible day to day.&lt;/p&gt;

&lt;p&gt;Just because a piece of software can do five different things if you change various settings doesn’t mean it should. Users shouldn’t have to think to hard about how to navigate through the tool in front of them. If complexity is required, then ease of use becomes a higher priority. &lt;/p&gt;

&lt;p&gt;The same goes with building the software itself. If a function is difficult to understand and use because it does many things at once, it is not “at hand”. The balance of making something easy lies in the difficulty in creating that ease. More thought is required before code is written and the initial effort’s worth has to be weight against the end result’s usability. &lt;/p&gt;

&lt;h2&gt;
  
  
  Beauty and a sense of space even when there isn’t much actual space is vital to livability.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;(the culmination of all the planning and building needs to be a livable space that’s comfortable)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Windows are a massive factor in a tiny house. Those with few or very small ones tend to feel tighter, more cramped, less livable. Beauty is an even more important factor here than in a larger home, where the lack can be compensated for with furniture, decor, and other additions.&lt;/p&gt;

&lt;p&gt;Software, too, needs to have a sense of space and beauty in the both the interface and in the code itself. Cramming too much functionality into an interface makes it feel less useable. Writing code that tries to do too much with each function becomes not only fragile, but also difficult to debug and maintain, never mind adding new features.&lt;/p&gt;

&lt;p&gt;All of the work put into building a piece of software, regardless of the platform, needs to result in a code base that’s maintainable and flexible and a UI/UX that meets a user’s needs and guides them through the process of getting there without unnecessary work or distraction.&lt;/p&gt;

&lt;p&gt;I hope this exploration gave you something to think about as you sit down to write that next line of code. I know it has me thinking differently as I approach my day to day work and also as I prepare to start any new projects in the future. Compact, concise, beautiful, usable, the tiny house philosophy turns out to be a great way to write software, too.&lt;/p&gt;

&lt;p&gt;(originally published on &lt;a href="http://jenniferlynparsons.github.io/software-a-tiny-house/"&gt;http://jenniferlynparsons.github.io&lt;/a&gt;)&lt;/p&gt;

</description>
      <category>programming</category>
      <category>inspiration</category>
    </item>
    <item>
      <title>Let’s Talk About HTML Hierarchy</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Wed, 01 Nov 2017 22:57:09 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/lets-talk-about-html-hierarchy-ec3</link>
      <guid>https://dev.to/jenniferlynparsons/lets-talk-about-html-hierarchy-ec3</guid>
      <description>&lt;p&gt;Okay, this is our meat and potatoes, right? HTML is the backbone of how we put a website together. At some point, no matter what framework, JS, Ruby, etc. fanciness we’re using to build a site, we’re going to spit HTML out at the end to be ingested by some sort of browser. &lt;/p&gt;

&lt;p&gt;We don’t know what kind of browser will be reading our code. We only know that it will be able to read it. Firefox, Chrome, Internet Explorer and Safari are usually what pop into people’s heads when you say the word “browser”. It might be desktop or mobile, but there are many other browsers out there. In particular, the ones that get forgotten most often are screen readers, those browsers that are accessible to those with visual limitations of one from or another. &lt;/p&gt;

&lt;p&gt;What these limited browsers also do, in addition to being incredible tools for the visually impaired to gain access to the internet, is also display the power and importance of using semantic elements in our HTML structures. &lt;/p&gt;

&lt;p&gt;Frankly, we should all be more concerned about accessibility (myself included) but even if you’re not for some reason, this information is useful to everyone for another reason: this is also how search engines read your page. Want better page rankings? Using HTML properly will help you out. The bots will be able to determine what the most important information is on the page. This, in turn, tells the search engine what your page is about and whether to serve your link up higher on the results page when someone searches for something related to your page. &lt;/p&gt;

&lt;p&gt;There is a third important reason to write your HTML semantically: it makes it easier to write CSS and you’ll have to write less of it. I’ll get into that at another time, but suffice to say that there is magic sauce in the mix between semantic HTML and the power of the cascade.&lt;/p&gt;

&lt;p&gt;So, with all that said, what does it mean to write “semantic HTML? It means that the content that we’re adding to our page has context. It has hierarchy, levels of importance that help tell the browsers what to emphasize and what to deemphasize. It helps describe the data that we’re displaying on the page so our users (don’t forget the users!) don’t have to think too hard about what they’re looking at. We want them to intuitively understand our page as much as possible. &lt;/p&gt;

&lt;p&gt;Okay, perhaps an example here would be helpful. Take a look at this chunk of information:&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/http%3A%2F%2Fjenniferlynparsons.github.io%2Fassets%2Fimg%2Fposts%2Fhtmlexample1.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/http%3A%2F%2Fjenniferlynparsons.github.io%2Fassets%2Fimg%2Fposts%2Fhtmlexample1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now this one:&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/http%3A%2F%2Fjenniferlynparsons.github.io%2Fassets%2Fimg%2Fposts%2Fhtmlexample2.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/http%3A%2F%2Fjenniferlynparsons.github.io%2Fassets%2Fimg%2Fposts%2Fhtmlexample2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, you may have parsed out that the bit of this wikipedia article is about the Drabble fiction form &lt;a href="https://en.wikipedia.org/wiki/Drabble" rel="noopener noreferrer"&gt;Drabble - Wikipedia&lt;/a&gt;, but what was less clear was that “Criteria is a subsection of “55 Fiction”. In both examples above, that’s raw html rendered in Firefox, by the way. No CSS or anything fancy other than setting a width for the body so I could take a nice screenshot. &lt;/p&gt;

&lt;p&gt;In the first example, all the chunks of information are wrapped in &lt;code&gt;p&lt;/code&gt; tags. In the second, we have a structure that looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which, if we were to think of this accurately and with some indenting to clarify the hierarchy, is a page outline and could be thought of like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Title&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;information related to the title&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Subtitle&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;information related to the subtitle&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Subtitle&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;information related to the subtitle&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

      &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;Sub Subtitle&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;information related to the subsubtitle&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only reason in the first example that you can discern the headlines is because they are short and they are in separate &lt;code&gt;p&lt;/code&gt; tags, which by default in Firefox have margin around them. &lt;/p&gt;

&lt;p&gt;Two slightly more extreme examples for you. The first, which uses only &lt;code&gt;div&lt;/code&gt; elements, which are rendered by default as blocks similar to &lt;code&gt;p&lt;/code&gt; tags, but without any margins. They are “styleless by default:&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/http%3A%2F%2Fjenniferlynparsons.github.io%2Fassets%2Fimg%2Fposts%2Fhtmlexample3.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/http%3A%2F%2Fjenniferlynparsons.github.io%2Fassets%2Fimg%2Fposts%2Fhtmlexample3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second contains only &lt;code&gt;span&lt;/code&gt; tags, which are inline elements really meant  for styling and grouping data with similar attributes such as phrases that are in a different language:&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/http%3A%2F%2Fjenniferlynparsons.github.io%2Fassets%2Fimg%2Fposts%2Fhtmlexample4.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/http%3A%2F%2Fjenniferlynparsons.github.io%2Fassets%2Fimg%2Fposts%2Fhtmlexample4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yeah, things are starting to get hard to parse now, right? And yet, in both these examples, there are the same number of html tags, wrapping the information in exactly the same way as in the first two examples.&lt;/p&gt;

&lt;p&gt;It has been argued to me that tags like &lt;code&gt;h1&lt;/code&gt; and &lt;code&gt;article&lt;/code&gt;, etc. only encode style. In theory, this may be true. Tags are just an abstract way of displaying information in organized chunks and their names don’t matter. If we had collectively decided to identify semantics with class names, &lt;code&gt;div.h1&lt;/code&gt; would have the same importance as &lt;code&gt;h1&lt;/code&gt;. However, this is not the paradigm we work in and so &lt;code&gt;h1&lt;/code&gt; still holds more semantic weight in the page hierarchy and browsers are engineered with stylistic defaults to match that hierarchy.&lt;/p&gt;

&lt;p&gt;Semantic HTML goes beyond just headers and paragraphs.  &lt;code&gt;section&lt;/code&gt;,  &lt;code&gt;article&lt;/code&gt;, &lt;code&gt;header&lt;/code&gt;,&lt;code&gt;footer&lt;/code&gt;, and a few other special tags all help not only organize your content and make it easier to style, but also contribute to making your HTML make more sense both to the browser and to the user reading your page. While they don’t have any default styling associated with them, once again, screen readers and SEO concerns benefit greatly from proper usage of these tags.&lt;/p&gt;

&lt;p&gt;I hope this has helped clarify a few things about how the HTML hierarchy works and how you can use it to provide your users with a better experience.  To help you along the way, I’ll be posting a follow up on some tips for writing better code that outlines some common mistakes I’ve seen and more thoughts on writing cleaner, more performant HTML. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Some final notes and resources:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I highly recommend reading this article for a brief but thorough overview on screen reader capabilities and how semantics can improve the experience for the visually impaired: &lt;br&gt;
&lt;a href="https://webaim.org/techniques/screenreader/" rel="noopener noreferrer"&gt;WebAIM: Designing for Screen Reader Compatibility&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to go more in depth in understanding semantic HTML? This is a great resource: &lt;br&gt;
&lt;a href="https://internetingishard.com/html-and-css/semantic-html/" rel="noopener noreferrer"&gt;Semantic HTML Tutorial | HTML &amp;amp; CSS Is Hard&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a bit more nitty gritty overview of the various tags mentioned here, as well as plenty others, there are few better resources than the MDN. Their list of tags conveniently breaks them down by intended usage:&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element" rel="noopener noreferrer"&gt;HTML element reference - HTML | MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A few updates:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Too often framework users make &lt;em&gt;everything&lt;/em&gt; a div. That's bad for users, search engines, and even devs making changes!&lt;br&gt;
&lt;a href="https://twitter.com/jasonrstumpf/status/925882900557336576" rel="noopener noreferrer"&gt;Jason Stumpf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As I thought a bit further about the topic, I also thought of a few more use cases you may not have considered:&lt;br&gt;
â€¢ print/pdf versions of your page (and epub if you do that kind of thing) are much easier to generate when a proper page hierarchy is used.&lt;br&gt;
â€¢ RSS readers ingest the html sent over without any styling attached. If you’d like your headlines and general page structure to translate into other interfaces with clarity, semantic HTML is the way to go.&lt;/p&gt;

</description>
      <category>html</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>I learned a lot, but how much?</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Sun, 15 Oct 2017 03:53:34 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/i-learned-a-lot-but-how-much-9ie</link>
      <guid>https://dev.to/jenniferlynparsons/i-learned-a-lot-but-how-much-9ie</guid>
      <description>&lt;p&gt;We’re often told in programming that personal projects are, in addition to being a great way to build a portfolio of work to show prospective employers, a method for learning new things. That’s totally true. Personal projects, especially if we’re working solo, can provide challenges that will help us learn combined with the freedom to pursue this work at our own pace and in whatever area we’re interested in exploring.&lt;/p&gt;

&lt;p&gt;So, how do we tackle a personal project? We sit down, plan it, code it, tweet about it and then after boatload of work and the excitement of launching, we’re done, right? I often have had the sense that I learned “so much by working on something.&lt;/p&gt;

&lt;p&gt;Sure. But what exactly have we learned? Has this been useful to us beyond the project existing for ourselves and others to use? How do we gauge the value of this experience in terms of our education and growth?&lt;/p&gt;

&lt;p&gt;For me, the answer lies in something many of us who work in Agile paradigms are already familiar with, but with a slightly different focus: The retrospective.&lt;/p&gt;

&lt;p&gt;Fairly recently I’ve started doing a retrospective session to see what I got out of doing a particular personal project. If you wanted, you could even do a solo sprint and retrospective pattern of work as well. These retrospectives help me to gain insights into what worked, what didn’t, etc. Surprising things turn up as I write about the project I just completed.&lt;/p&gt;

&lt;p&gt;When I’m done I have an immediate and thorough understanding of what I’ve just done and what I learned along the way. An added benefit is that as long as I keep doing this, I’ll have a record I can look back on of what I was thinking in the moment and what the most distinct aspects of the project were for me at the time.&lt;/p&gt;

&lt;p&gt;I also take a little time to reflect on what I learned about myself as a person in doing the project. What kind of choices I made, how I reacted to the challenges and hurdles I encountered, and what parts were satisfying or interesting to me. This can help lead my choices for future projects as well as areas that might be interesting to pursue in my study and work choices.&lt;/p&gt;

&lt;p&gt;It does take a bit of extra time and effort to do this, but not overly much and it’s been worth doing so far. If you’d like to try it out yourself, here’s my template to use as a starting point for your own:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Challenges going into the project:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What resources did I have to mitigate these challenges? (People, books, sites, etc)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How did I prepare for the project?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Challenges during the process:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Where did I get really stuck?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How did I overcome those hurdles?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Could I have done it better and what would that have taken?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If this project exposed knowledge gaps, what do I need to learn?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What did I learn from this project?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Technologically:&lt;/li&gt;
&lt;li&gt;Personally:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devtips</category>
    </item>
    <item>
      <title>Hi, I'm Jennifer Lyn Parsons</title>
      <dc:creator>Jennifer Lyn Parsons</dc:creator>
      <pubDate>Sat, 11 Mar 2017 19:56:40 +0000</pubDate>
      <link>https://dev.to/jenniferlynparsons/hi-im-jennifer-lyn-parsons</link>
      <guid>https://dev.to/jenniferlynparsons/hi-im-jennifer-lyn-parsons</guid>
      <description>&lt;p&gt;I have been coding for 6+ years professionally, 16+ years as a hobbyist. Though I did spend some time with BASIC back in the early 80s so 34 years, depending on your definition. &lt;/p&gt;

&lt;p&gt;You can find me on GitHub as &lt;a href="https://github.com/jenniferlynparsons" rel="noopener noreferrer"&gt;jenniferlynparsons&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in New Jersey (don't look at me like that).&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: HTML/CSS, JavaScript (vanilla, JQuery, React)&lt;/p&gt;

&lt;p&gt;I am currently learning more about Clojure, OOP, functional programming, Python, back end technologies, and how to be a better version of myself.&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
