<?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: Mj Tapiru</title>
    <description>The latest articles on DEV Community by Mj Tapiru (@jhynzar).</description>
    <link>https://dev.to/jhynzar</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%2F205579%2F0418e4f2-ade9-4373-a84e-6c7787ec1ef9.png</url>
      <title>DEV Community: Mj Tapiru</title>
      <link>https://dev.to/jhynzar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jhynzar"/>
    <language>en</language>
    <item>
      <title>Code Duplication Refactoring on Conditional Conditions</title>
      <dc:creator>Mj Tapiru</dc:creator>
      <pubDate>Mon, 09 Sep 2019 03:36:20 +0000</pubDate>
      <link>https://dev.to/jhynzar/code-duplication-refactoring-on-conditional-conditions-3h10</link>
      <guid>https://dev.to/jhynzar/code-duplication-refactoring-on-conditional-conditions-3h10</guid>
      <description>&lt;p&gt;Sometimes you come accross duplicated code blocks that the only difference is having an additional condition to check if another condition is true. An Example of the Idea is given below.&lt;/p&gt;

&lt;h2&gt;
  
  
  From
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;condition1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;condition2&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//doSomething1&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;conditionA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;conditionB&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//doSomething2&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;condition1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//doSomething1&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;conditionA&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//doSomething2&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;In the above example, the only difference is if &lt;code&gt;condition2 == true&lt;/code&gt; then check for &lt;code&gt;conditionB&lt;/code&gt;&lt;br&gt;
To refactor it, we leave all execution rights to &lt;code&gt;condition2&lt;/code&gt; and &lt;code&gt;conditionB&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Assume:&lt;br&gt;&lt;br&gt;
&lt;code&gt;condition1 = true&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;conditionA = false&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;with that, we get:&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;condition2&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//doSomething1&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;conditionB&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//doSomething2&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="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//doSomething1&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//doSomething2&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;blockquote&gt;
&lt;p&gt;In the above example in the first &lt;code&gt;if&lt;/code&gt; block, you will only execute &lt;code&gt;doSomething2&lt;/code&gt;, if and only if &lt;code&gt;condition2&lt;/code&gt; AND &lt;code&gt;conditionB&lt;/code&gt; are &lt;code&gt;true&lt;/code&gt;.&lt;br&gt;
So we can refactor it to the code below.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  To
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;condition1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//doSomething1&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;conditionA&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition2&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;conditionB&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="c1"&gt;//doSomething2&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;Codepen Example: &lt;a href="https://codepen.io/jhynzar/pen/QRJpob?editors=0012"&gt;https://codepen.io/jhynzar/pen/QRJpob?editors=0012&lt;/a&gt;&lt;/p&gt;

</description>
      <category>refactorit</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Gamedev, Where should I start?</title>
      <dc:creator>Mj Tapiru</dc:creator>
      <pubDate>Tue, 03 Sep 2019 02:46:00 +0000</pubDate>
      <link>https://dev.to/jhynzar/gamedev-where-should-i-start-3da1</link>
      <guid>https://dev.to/jhynzar/gamedev-where-should-i-start-3da1</guid>
      <description>&lt;h3&gt;
  
  
  Hi! I was hoping to get started on Game Development.
&lt;/h3&gt;

&lt;p&gt;I'm currently a web developer and is decent in javascript. I've tried Unity before and made an incomplete but working Endless Runner Game.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Since I have confidence in my javascript coding skills,&lt;/em&gt; &lt;strong&gt;I'm hoping to learn gamedev on web&lt;/strong&gt; and I have my sight on PhaserJs. Do you have any tips or links on resources I could use? Or any suggestions for another framework in gamedev on web? If you have any-, anything at all. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I WOULD LOVEEEEE IT&lt;/strong&gt; if you could share. ^^ &lt;/p&gt;

&lt;p&gt;Also if you would be so kind as to mentor me on the steps, I would gladly appreciate it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hoping to see great comments and suggestions. Thanks!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>discuss</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
