<?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: Adam Friedl</title>
    <description>The latest articles on DEV Community by Adam Friedl (@adamfriedl).</description>
    <link>https://dev.to/adamfriedl</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%2F18318%2F71fad2e9-a686-4f03-8260-84bbce0abffa.JPG</url>
      <title>DEV Community: Adam Friedl</title>
      <link>https://dev.to/adamfriedl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adamfriedl"/>
    <language>en</language>
    <item>
      <title>Learning and Working and Family-ing</title>
      <dc:creator>Adam Friedl</dc:creator>
      <pubDate>Wed, 07 Mar 2018 15:15:59 +0000</pubDate>
      <link>https://dev.to/adamfriedl/learning-and-working-and-family-ing--30c3</link>
      <guid>https://dev.to/adamfriedl/learning-and-working-and-family-ing--30c3</guid>
      <description>&lt;p&gt;There are literally thousands of resources these days that can help you learn how to code. Do you have the desire and the grit? You can become a software developer. This is definitely true as far as it goes, but it often silently assumes that you have an infinite supply of other equally important resources — namely time. If that's true for you, mazel! Take advantage. But, for many of us, it isn't true — particularly those raising young kids and working full-time.&lt;/p&gt;

&lt;p&gt;All of that is to say how much I really appreciated hearing a recent &lt;a href="https://www.codenewbie.org/podcast/which-javascript-framework-should-you-learn"&gt;episode&lt;/a&gt; of the CodeNewbie podcast that took a minute to shout out to those folks. The ridiculously talented &lt;a href="https://twitter.com/sarah_edo"&gt;Sarah Drasner&lt;/a&gt; and always-awesome host &lt;a href="https://twitter.com/saronyitbarek"&gt;Saron Yitbarek&lt;/a&gt; took a minute to say "props to you all! We don't know how you do it," and it's hard to express how validating that felt.&lt;/p&gt;

&lt;p&gt;When I try to convey to folks how passionate I am about coding, I explain that I went through an online bootcamp when my daughter was an infant and I was working a full-time lawyer job. I try to take advantage of every free second to learn or practice. I still frequently get up at 4:30am and stay up late into the night to make the time. I'm hardly alone. There are so many of us, many folks with time crunches much more challenging than my own. They're sacrificing sleep and family time because they love this thing and want to be good at it.&lt;/p&gt;

&lt;p&gt;I've often found it frustrating that there is not more discussion of this topic in the dev community online. So many thanks to Saron and Sarah for the good words!&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>productivity</category>
    </item>
    <item>
      <title>A Parade of Text Editors</title>
      <dc:creator>Adam Friedl</dc:creator>
      <pubDate>Mon, 15 Jan 2018 15:59:43 +0000</pubDate>
      <link>https://dev.to/adamfriedl/a-parade-of-text-editors-45fp</link>
      <guid>https://dev.to/adamfriedl/a-parade-of-text-editors-45fp</guid>
      <description>&lt;p&gt;I suspect that many folks attracted to programming share this trait, but long before I ever read a line of code, I was particular about my "tools." I'd spend hours trying different pens, or search all over town for a notebook with just the right size, binding, paper thickness and ruling (dot grid, anyone?). And occasionally I'd find a setup that really made me happy, although I could never shake the idea that there might be something out there just a &lt;em&gt;little&lt;/em&gt; bit better.&lt;/p&gt;

&lt;p&gt;When I got interested in coding a few years back, the only text editor I knew of was &lt;a href="https://www.barebones.com/products/textwrangler/"&gt;Text Wranger&lt;/a&gt;. That's what this guy at work used, and I thought he must be a genius coder (later I realized that he'd never learned CSS and laid out web pages with HTML tables). I started watching lots of web tutorials online, and it wasn't long before I saw someone open &lt;a href="https://www.sublimetext.com/"&gt;Sublime Text&lt;/a&gt; (he just called it "Sublime," because he was cool like that). And I soon found that Sublime Text was in fact pretty awesome. You could spend (waste(?)) days perusing all the different extensions and options. &lt;/p&gt;

&lt;p&gt;As great as Sublime Text was, though, I always had my eye out for something better. When I finally got serious about coding and attended an immersive program, they recommended &lt;a href="https://atom.io/"&gt;Atom&lt;/a&gt;, which was the new-ish kid on the block. I used it for most of a year and it has a lot to recommend it: it's free (which Sublime Text definitely wasn't), open-source, built by Github. What's not to like? Well, mainly that it's painfully slow to start up and hangs often... So when I saw one of my coding heroes using &lt;a href="https://code.visualstudio.com/"&gt;Visual Studio Code&lt;/a&gt;, you know what happened next. &lt;/p&gt;

&lt;p&gt;VS Code is the best text editor I've come across. It's quick and flexible. It has a seamless integrated terminal and a robust ecosystem of extensions. As someone who currently writes mostly JavaScript, I find its version of tools like ESLint, Prettier, npm Intellisense, as well as snazzy visuals like VS Code Great Icons, to be easy to incorporate.&lt;/p&gt;

&lt;p&gt;Is there still something better out there? Probably! Let me know what you think.  &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>texteditors</category>
      <category>javascript</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Hoist with his own JS Petard</title>
      <dc:creator>Adam Friedl</dc:creator>
      <pubDate>Tue, 12 Dec 2017 12:49:17 +0000</pubDate>
      <link>https://dev.to/adamfriedl/hoist-with-his-own-js-petard-bmh</link>
      <guid>https://dev.to/adamfriedl/hoist-with-his-own-js-petard-bmh</guid>
      <description>

&lt;p&gt;In JavaScript, &lt;em&gt;hoisting&lt;/em&gt; refers to the idea that declarations — of both variables and functions — are automatically moved to the top of their scope. Note that this doesn't mean they are &lt;em&gt;physically moved in your file&lt;/em&gt;. Rather, it's shorthand for explaining a key aspect of &lt;a href="http://davidshariff.com/blog/what-is-the-execution-context-in-javascript/"&gt;execution context&lt;/a&gt; — specifically, the order in which the JavaScript interpreter, well, interprets the information in any given scope. We'll illustrate with some examples in a minute, but, first, an important question: what does "hoist" even mean?&lt;/p&gt;

&lt;h2&gt;
  
  
  Liberal Arts Interlude
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Hoist&lt;/em&gt; is a mid 15th-century English word &lt;a href="http://www.etymonline.com/index.php?term=hoist"&gt;derived&lt;/a&gt; from similar words in other Germanic languages (e.g., Dutch and Low German) meaning "to lift up" or "to raise." Its most famous use in English is undoubtedly by our friend Shakespeare, in &lt;em&gt;Hamlet&lt;/em&gt;. Hamlet, realizing that his supposed friends are actually carrying a letter with Hamlet's death warrant, secretly alters the letter so that they will be killed instead, and remarks "&lt;em&gt;For 'tis the sport to have the enginer / Hoist with his own petar'.&lt;/em&gt;" A &lt;a href="https://en.wikipedia.org/wiki/Petard"&gt;petard&lt;/a&gt; was a small bomb used by military engineers, raised onto gates or obstacles to blow them up when breaching a fortification, and, so, to &lt;em&gt;hoist with his own petard&lt;/em&gt; became an English idiom meaning "to blow oneself up with his own bomb" or "to fall into one's own trap." A bit like what can happen to the software engineer who doesn't take &lt;em&gt;hoisting&lt;/em&gt; into account when putting together JS code.&lt;/p&gt;

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

&lt;p&gt;So, back to it. The JS interpreter in the browser works as a single thread, meaning only one thing can happen at a time. Every time it considers a new scope, it does these several things in the same order. Among them are &lt;em&gt;looking through the entire scope for function and variable declarations&lt;/em&gt; and &lt;em&gt;executing functions and assigning values to variables&lt;/em&gt; — the former always before the latter. The practical effect is to interpret the code as if all declarations were &lt;em&gt;hoisted&lt;/em&gt; to the top of their respective scopes, while assignments stay in their original places. For example:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;badDude = 'Kylo Ren';
var badDude;
console.log(badDude) // prints 'Kylo Ren'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Even though we never assigned a value to &lt;code&gt;badDude&lt;/code&gt; after declaring it as a variable, it still logs 'Kylo Ren' because the declaration was hoisted to the top of the scope before the code was executed, as if we had written:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var badDude;
badDude = 'Kylo Ren';
console.log(badDude) // prints 'Kylo Ren'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that this is the case for variable &lt;em&gt;and&lt;/em&gt; function declarations. In fact, function declarations are hoisted first.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;goat(); // prints "Messi is the greatest of all time!"

function goat() {
  console.log("Messi is the greatest of all time!");
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here we declare the function in the global scope, the same scope in which &lt;code&gt;goat()&lt;/code&gt; is called, and thus the function declaration was hoisted to the top of the global scope, &lt;em&gt;above&lt;/em&gt; the function call.&lt;/p&gt;

&lt;p&gt;Note that this is not the case, however, when a function is the assigned value of a variable. If we modified our example so that it read:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;goat(); // undefined

var goat = () =&amp;gt; {
  console.log("Messi is the greatest of all time!");
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;var goat&lt;/code&gt; is hoisted to the top, but the expression assigned to it stays in place — below the function call — so that &lt;code&gt;goat()&lt;/code&gt; prints &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Remember the Scope!
&lt;/h2&gt;

&lt;p&gt;Declarations are hoisted to the top of their &lt;em&gt;scope&lt;/em&gt;, not necessarily to the top of the file. For example:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var leadSinger = 'Diamond Dave';

(function vanHalen() {

  console.log('First lead singer was ' + leadSinger);  // prints undefined

  var leadSinger = 'Sammy Hagar';
  console.log('Second lead singer was ' + leadSinger); // prints "Sammy Hagar"
})()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;How anyone might not know that David Lee Roth was the first (and only true) lead singer of Van Halen is beyond me, but that's JavaScript for you. Here, the &lt;em&gt;re&lt;/em&gt;-declaration of leadSinger variable jumps to the top of its scope (in this case, the local or function scope), while its assignment stays in place. It overwrites the assignment made in the global scope and is thus undefined when we arrive at the first &lt;code&gt;console.log()&lt;/code&gt;. If we wanted to to give Diamond Dave his due, we could simply not re-declare &lt;code&gt;leadSinger&lt;/code&gt;, but just reassign it.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var leadSinger = 'Diamond Dave';

(function vanHalen() {

  console.log('First lead singer was ' + leadSinger);  // prints "Diamond Dave"

  leadSinger = 'Sammy Hagar';
  console.log('Second lead singer was ' + leadSinger); // prints "Sammy Hagar"
})()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;




</description>
      <category>javascript</category>
      <category>hoisting</category>
      <category>shakespeare</category>
      <category>vanhalen</category>
    </item>
  </channel>
</rss>
