<?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: Luiz Lopes</title>
    <description>The latest articles on DEV Community by Luiz Lopes (@theprivileges).</description>
    <link>https://dev.to/theprivileges</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%2F100408%2F74433ad1-7798-450d-8052-a335c69679a4.png</url>
      <title>DEV Community: Luiz Lopes</title>
      <link>https://dev.to/theprivileges</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/theprivileges"/>
    <language>en</language>
    <item>
      <title>DeFi Connected — Terra Hackathon</title>
      <dc:creator>Luiz Lopes</dc:creator>
      <pubDate>Mon, 19 Apr 2021 22:42:28 +0000</pubDate>
      <link>https://dev.to/delphidigital/defi-connected-terra-hackathon-2jfi</link>
      <guid>https://dev.to/delphidigital/defi-connected-terra-hackathon-2jfi</guid>
      <description>&lt;p&gt;DeFi isn’t rebuilding finance, it’s dismantling it. In its place, we build something so powerful it’ll change humanity’s fate. We are &lt;a href="https://www.ideocolab.com/ventures/" rel="noopener noreferrer"&gt;IDEO Colab Ventures&lt;/a&gt;, &lt;a href="https://www.delphidigital.io/delphi-labs-intro/" rel="noopener noreferrer"&gt;Delphi Labs&lt;/a&gt; and &lt;a href="https://terra.money/" rel="noopener noreferrer"&gt;Terra&lt;/a&gt;. We want to join forces with &lt;strong&gt;YOU&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Join our 48h Terra Hackathon; lets build the next gen of DeFi together.&lt;/p&gt;

&lt;h3&gt;
  
  
  What you get as a participant
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Access to Delphi Labs big brain support&lt;/li&gt;
&lt;li&gt;IDEO product design tutorship&lt;/li&gt;
&lt;li&gt;A chance to join our incubation program — with further access to funding and support from both Delphi Labs and IDEO Colab. Our team is working 24/7 helping to unlock the potential of DeFi.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;IDEO Colab Ventures and Delphi Labs are investors &amp;amp; supporters of many disruptive teams, including:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://optimism.io/" rel="noopener noreferrer"&gt;Optimism&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://thorchain.org/" rel="noopener noreferrer"&gt;Thorchain&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://near.org/" rel="noopener noreferrer"&gt;Near&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aave.com/" rel="noopener noreferrer"&gt;Aave&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://synthetix.io/" rel="noopener noreferrer"&gt;Synthetix&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We see the walls to mainstream adoption. And we want to incubate builders to break them down. That’s why we chose to join forces with Terra and &lt;a href="https://twitter.com/d0h0k1" rel="noopener noreferrer"&gt;Do Kwon&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;They're solving many of the hardest problems in crypto:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On-ramps&lt;/li&gt;
&lt;li&gt;Accessible UI&lt;/li&gt;
&lt;li&gt;Developer on-boarding tools with Terra projects like Saturn, Alice, and Anchor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;So what actually will happen in the initial 48h event?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Delphi Labs and IDEO experts will lead your early-stage team through a design research sprint, as you talk to real end users and collaborate with peers, experts, and mentors in the DeFi community. &lt;/li&gt;
&lt;li&gt;A small number of the most promising teams will be invited to the full 11-week residency.  During this time each team will be assigned a senior member of Delphi Labs or IDEO as a mentor and have regular sessions with the wider team to share progress, get guidance and feedback.&lt;/li&gt;
&lt;li&gt;At the end of the residency we expect that one or more of the projects will be offered full incubation.  Allowing us to fund the projects from IDEO VC, Delphi Ventures and Delphi Labs while also providing deeper UI/visual design, token econ and hiring support.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to get involved?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Submit your 1-minute application by &lt;strong&gt;Tuesday, April 27, 2021 at 00:00 (GMT+3)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;We do not care where you are, or where you’ve been.We care about what you dream of building&lt;/li&gt;
&lt;li&gt;Apply here: &lt;a href="https://eventornado.com/event/defi-connected" rel="noopener noreferrer"&gt;https://eventornado.com/event/defi-connected&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Original Twitter 🧵: &lt;a href="https://twitter.com/IDEOVC/status/1377377343421833220" rel="noopener noreferrer"&gt;https://twitter.com/IDEOVC/status/1377377343421833220&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Looking for ideas?
&lt;/h3&gt;

&lt;p&gt;José Maria Macedo from Delphi Labs composed a &lt;a href="https://twitter.com/ZeMariaMacedo/status/1382799094188544004" rel="noopener noreferrer"&gt;wish-list&lt;/a&gt; of ideas that no one is yet building on Terra. &lt;/p&gt;

</description>
      <category>hackathon</category>
      <category>announcement</category>
      <category>crypto</category>
    </item>
    <item>
      <title>The Case For Expression Reduction</title>
      <dc:creator>Luiz Lopes</dc:creator>
      <pubDate>Mon, 20 Apr 2020 15:30:47 +0000</pubDate>
      <link>https://dev.to/theprivileges/the-case-for-expression-reduction-2mbb</link>
      <guid>https://dev.to/theprivileges/the-case-for-expression-reduction-2mbb</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally posted at &lt;a href="https://wickeddeveloper.com/development/a-case-for-expression-reduction" rel="noopener noreferrer"&gt;wickeddeveloper.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As a software developer you will inevitably have to debug some piece of code you wrote months if not years ago, or code from a colleague that is no longer part of your team.  As you step through some routine you notice an array of conditional statements with complicated conditional expressions. As you search for the bug in the code you'll end up noticing that you can't hold all of the values in your head.  You can no longer remember what a particular value means or what it points to. &lt;/p&gt;

&lt;p&gt;I have found that creating boolean variables that hold the value of an expensive or complicated expression makes it easier to read and understand code. &lt;/p&gt;

&lt;p&gt;Let's look at a trivial piece of code, written in JavaScript, and see how assigning complex conditions to a variable makes it much easier to understand and read the code. &lt;em&gt;Keep in mind this code is not something you'd use in production, I'm only using this to illustrate the point.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Suppose there is a &lt;code&gt;function&lt;/code&gt; that takes an argument called &lt;code&gt;drink&lt;/code&gt; and inside of this function we check what type of drink it is and return an emoji of a coffee, tea, or milk.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* Assume COFFEE, CAFE, LATE, MOCHA, TEA, etc are imported into this module. */&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getDrinkEmoji&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;drink&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;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;COFFEE&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
        &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;CAFE&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
        &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;LATE&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
        &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;MOCHA&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;span class="k"&gt;else&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;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;TEA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
               &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;BLACK_TEA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
               &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;GREEN_TEA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
               &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;OOLONG_TEA&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;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="s1"&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reading through code like that requires you to hold quite a lot in your head.&lt;/p&gt;

&lt;p&gt;Now let's look at the same code but having assigned the expression to a variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getDrinkEmoji&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;drink&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isCoffee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;COFFEE&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                     &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;CAFE&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                     &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;LATE&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                     &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;MOCHA&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isTea&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;TEA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                  &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;BLACK_TEA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                  &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;GREEN_TEA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                  &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;OOLONG_TEA&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;isCoffee&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;span class="k"&gt;else&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;isTea&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;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="s1"&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can more quickly understand what the expressions inside of the &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;else if&lt;/code&gt; are evaluating to.&lt;/p&gt;

&lt;p class="highlight hll plaintext"&gt;
📌 You may also prefix your variables with words like &lt;code&gt;has&lt;/code&gt;, &lt;code&gt;should&lt;/code&gt;, &lt;code&gt;was&lt;/code&gt;, etc.
&lt;/p&gt;

&lt;p&gt;This pattern makes a lot of sense when you find yourself evaluating the condition multiple times.  When you do it once you can just reference the variable again when you need it. &lt;/p&gt;

&lt;p&gt;In this next example, our &lt;code&gt;function&lt;/code&gt; receives an array of &lt;code&gt;drinks&lt;/code&gt;, we use the &lt;a href="https://devdocs.io/javascript/global_objects/array/some" rel="noopener noreferrer"&gt;&lt;code&gt;Array.some&lt;/code&gt;&lt;/a&gt; method to test whether the &lt;code&gt;drinks&lt;/code&gt; include a coffee or a tea and then return an emoji.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getDrinksEmoji&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;drinks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hasCoffee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;drinks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;COFFEE&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                                           &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;CAFE&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                                           &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;LATE&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                                           &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;MOCHA&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hasTea&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;drinks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;TEA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
                                        &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;BLACK_TEA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                                        &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;GREEN_TEA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; 
                                        &lt;span class="nx"&gt;drink&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;OOLONG_TEA&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hasCoffeeAndTea&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hasCoffee&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;hasTea&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;hasCoffeeAndTea&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;span class="k"&gt;else&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;hasCoffee&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;span class="k"&gt;else&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;hasTea&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;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="s1"&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We had to execute the expensive computation of testing if the &lt;code&gt;drinks&lt;/code&gt; include a coffee or tea once, we referenced that expression multiple times in our code without additional performance penalty, and the code is still easy to read and understand.&lt;/p&gt;

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

&lt;p&gt;Conditional statements are an invaluable tools in software development, they provide us with flow control to determine the output of our programs.  You'll inevitably run across them when writing and reading code.  If you are the author of the code, or reading code that you have control over, do yourself a favor and assign your expensive and complicated condition statements to variables with meaningful names.  Doing so will free up space in your head and your code will be much easier to read and understand. &lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://javascript.info/ifelse" rel="noopener noreferrer"&gt;JavaScript — Conditional Operators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Conditional_(computer_programming)" rel="noopener noreferrer"&gt;Conditional (computer programming)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-write-conditional-statements-in-javascript" rel="noopener noreferrer"&gt;How To Write Conditional Statements in JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cal-linux.com/tutorials/conditionals.html" rel="noopener noreferrer"&gt;Conditional Execution in C++&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Predicate_%28mathematical_logic%29" rel="noopener noreferrer"&gt;Predicate (mathematical logic)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Thanks&lt;/strong&gt; to Greg Timmerman, and &lt;a class="mentioned-user" href="https://dev.to/nicholascloud"&gt;@nicholascloud&lt;/a&gt; for reading a previous version of this post. &lt;a class="mentioned-user" href="https://dev.to/nicholascloud"&gt;@nicholascloud&lt;/a&gt; also gave this pattern a name (&lt;em&gt;expression reduction&lt;/em&gt;).&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Easy Way To Find Weekday From a Given Date String</title>
      <dc:creator>Luiz Lopes</dc:creator>
      <pubDate>Thu, 30 May 2019 22:17:33 +0000</pubDate>
      <link>https://dev.to/theprivileges/easy-way-to-find-weekday-from-a-given-date-string-le6</link>
      <guid>https://dev.to/theprivileges/easy-way-to-find-weekday-from-a-given-date-string-le6</guid>
      <description>&lt;p&gt;I've recently been introduced to the &lt;code&gt;Intl&lt;/code&gt; object, which is used as the namespace for the &lt;a href="https://norbertlindenberg.com/2012/12/ecmascript-internationalization-api/index.html" rel="noopener noreferrer"&gt;ECMAScript Internationalization API&lt;/a&gt;.  It has a neat object called &lt;code&gt;DateTimeFormat&lt;/code&gt; which can be used to format a date value into locale specific strings. &lt;/p&gt;

&lt;p&gt;I'll show you a typical use case for using &lt;code&gt;Intl.DateTimeFormat&lt;/code&gt; to generate the weekday of a given date string (e.g. &lt;code&gt;07/16/1945&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Given a &lt;code&gt;dateString&lt;/code&gt; in the format &lt;code&gt;MM/DD/YYYY&lt;/code&gt;, find and return the weekday for that date.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * Given a date string in the format MM/DD/YYY, find and return the 
 * weekday for that date in English.
 *
 * @param {string} dateString
 * @returns {string} - weekday for the given date [e.g: Wednesday]
 */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getWeekDay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dateString&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dateString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dateTimeFormatOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;weekday&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;long&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dateTimeFormat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;en-US&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dateTimeFormatOptions&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;dateTimeFormat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&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;
  
  
  Explanation
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create a function expression called &lt;code&gt;getWeekDay&lt;/code&gt; which takes a string (&lt;code&gt;dateString&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Create a &lt;code&gt;Date&lt;/code&gt; object with the given &lt;code&gt;dateString&lt;/code&gt;, so that we can pass it as a parameter into the &lt;code&gt;format&lt;/code&gt; method of &lt;code&gt;DateTimeFormat&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create an object to hold the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat#Parameters" rel="noopener noreferrer"&gt;&lt;code&gt;options&lt;/code&gt;&lt;/a&gt; parameter for &lt;code&gt;Intl.DateTimeFormat&lt;/code&gt;. Setting the &lt;code&gt;weekday&lt;/code&gt; property equals to &lt;code&gt;long&lt;/code&gt;, so that we get the localized weekday when calling &lt;code&gt;format&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create a an instance of &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat" rel="noopener noreferrer"&gt;&lt;code&gt;Intl.DateTimeFormat&lt;/code&gt;&lt;/a&gt; setting &lt;code&gt;locales&lt;/code&gt; to &lt;code&gt;en-US&lt;/code&gt;, and passing in the previously created &lt;code&gt;dateTimeFormatOptions&lt;/code&gt; object.&lt;/li&gt;
&lt;li&gt;Return the result of calling &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format" rel="noopener noreferrer"&gt;&lt;code&gt;format&lt;/code&gt;&lt;/a&gt; method on &lt;code&gt;Intl.DateTimeFormat&lt;/code&gt; to find the weekday for the given &lt;code&gt;date&lt;/code&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getWeekDay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;07/16/1945&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// expected output: "Monday"&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In closing, we used the &lt;code&gt;Intl.DateTimeFormat&lt;/code&gt; object to quickly find the weekday of a given date string. Best of all &lt;a href="https://caniuse.com/#feat=internationalization" rel="noopener noreferrer"&gt;&lt;code&gt;Intl&lt;/code&gt;&lt;/a&gt; has great support across modern browser. &lt;/p&gt;

&lt;p&gt;Thank you for reading. &lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>i18n</category>
    </item>
  </channel>
</rss>
