<?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: Chinoms</title>
    <description>The latest articles on DEV Community by Chinoms (@chinoms).</description>
    <link>https://dev.to/chinoms</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%2F1023450%2F3b8bf69e-da93-49b6-a3f0-75fe2999779d.jpeg</url>
      <title>DEV Community: Chinoms</title>
      <link>https://dev.to/chinoms</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chinoms"/>
    <language>en</language>
    <item>
      <title>Laravel Herd - an alternative to Laravel Valet</title>
      <dc:creator>Chinoms</dc:creator>
      <pubDate>Thu, 20 Jul 2023 12:12:57 +0000</pubDate>
      <link>https://dev.to/chinoms/laravel-herd-an-alternative-to-laravel-valet-bk9</link>
      <guid>https://dev.to/chinoms/laravel-herd-an-alternative-to-laravel-valet-bk9</guid>
      <description>&lt;p&gt;Read more about Laravel Herd here. You may be tempted to move away from Valet.&lt;br&gt;
&lt;a href="https://chinoms.com/what-is-laravel-herd-the-new-alternative-to-valet/"&gt;https://chinoms.com/what-is-laravel-herd-the-new-alternative-to-valet/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Wanna learn Vue JS</title>
      <dc:creator>Chinoms</dc:creator>
      <pubDate>Fri, 03 Mar 2023 20:29:58 +0000</pubDate>
      <link>https://dev.to/chinoms/wanna-learn-vue-js-2ki9</link>
      <guid>https://dev.to/chinoms/wanna-learn-vue-js-2ki9</guid>
      <description>&lt;p&gt;Hey, guys! So, I want to learn Vue JS on a budget, but I have Vue JS 2 courses. Can I go ahead, or do I just go for a Vue JS 3 course? &lt;/p&gt;

&lt;p&gt;Would this be a problem?&lt;/p&gt;

</description>
      <category>azure</category>
      <category>terraform</category>
      <category>devops</category>
      <category>cloudcomputing</category>
    </item>
    <item>
      <title>Why You Should Drop The 'Else' Keyword When Writing Conditionals</title>
      <dc:creator>Chinoms</dc:creator>
      <pubDate>Thu, 09 Feb 2023 06:08:05 +0000</pubDate>
      <link>https://dev.to/chinoms/why-you-should-drop-the-else-keyword-when-writing-conditionals-280i</link>
      <guid>https://dev.to/chinoms/why-you-should-drop-the-else-keyword-when-writing-conditionals-280i</guid>
      <description>&lt;p&gt;Without conditionals, programming would be impossible. From rookie coders to Silicon Valley nerds, we all use conditionals each day. One common conditional is the if-else construct. I greatly reduced my use of the else statement, and this helped me to greatly reduce my code complexity, enhance readability and maintainability. Let me explain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;canDrinkAlcohol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$age&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="nv"&gt;$age&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s2"&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Sorry, alcohol is not for you."&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;echo&lt;/span&gt; &lt;span class="s2"&gt;"You are free to drink alcohol."&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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"You must provide your age."&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="nf"&gt;canDrinkAlcohol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The snippet above shows how most people would write their code. First, there's a check to see if the an age was supplied at all. The other condition is nested inside of that condition. &lt;/p&gt;

&lt;p&gt;The code looks dirty. And if you throw in other conditions to be checked for, it becomes even dirtier and more confusing to read and difficult to maintain. &lt;/p&gt;

&lt;p&gt;But why should you seriously consider eliminating the use of 'else' in conditionals in your programming? A look at the code above will help answer this question.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Because the code flow is nonlinear, it is difficult to follow as the conditions are nested.&lt;/li&gt;
&lt;li&gt;It is difficult to identify which "else" corresponds to what "if."&lt;/li&gt;
&lt;li&gt;Error handling becomes difficult and confusing, and this is especially so when the code blog is big.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's rewrite the function and eliminate the nesting and the else statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;canDrinkAlcohol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$age&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="nv"&gt;$age&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&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;echo&lt;/span&gt; &lt;span class="s2"&gt;"You must provide your age."&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="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="nv"&gt;$age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Sorry, alcohol is not for you."&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="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"You are free to drink alcohol."&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="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;canDrinkAlcohol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You must have noticed a thing or two in the new function. The very first condition was reversed. I checked for the opposite of what was checked for in the first function. &lt;/p&gt;

&lt;p&gt;What was implemented in this new function is called the &lt;strong&gt;guard clause technique&lt;/strong&gt;. It is derived from the fail fast method, and the purpose is to validate a condition and immediately terminate code execution by throwing a meaningful error, rather than allowing the program to throw its own errors which are often less meaningful to the average user. To terminate code execution, I introduced the &lt;strong&gt;return&lt;/strong&gt; keyword.&lt;/p&gt;

&lt;p&gt;The new function is structured in such a way that the program exits at the earliest point of failure. The function keeps checking for conditions and the last part of the function doesn't have a condition because for the program to get to that point, all conditions have been checked and passed.&lt;/p&gt;

&lt;p&gt;Sometimes though, you will still absolutely need to use else statements and even nest if-else statements. In that case, you may wish to extract the nested conditionals into a separate function and chain the function or call it from within another function.&lt;/p&gt;

&lt;p&gt;Many people are taught that what I have done above - having multiple exit points in a function is bad programming practice. Well, it's actually bad programming to write unreadable code. &lt;/p&gt;

&lt;p&gt;As you can see, we can easily add conditionals to the function above without getting confused. Whenever you're coding, try to eliminate nesting. &lt;/p&gt;

</description>
      <category>education</category>
      <category>software</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
