<?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: hkly</title>
    <description>The latest articles on DEV Community by hkly (@hkly).</description>
    <link>https://dev.to/hkly</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%2F2990%2Fi6svcX0m.jpg</url>
      <title>DEV Community: hkly</title>
      <link>https://dev.to/hkly</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hkly"/>
    <language>en</language>
    <item>
      <title>Inspiration for the New Year: React and Tailwind</title>
      <dc:creator>hkly</dc:creator>
      <pubDate>Fri, 08 Jan 2021 21:51:43 +0000</pubDate>
      <link>https://dev.to/hkly/inspiration-for-the-new-year-react-and-tailwind-50og</link>
      <guid>https://dev.to/hkly/inspiration-for-the-new-year-react-and-tailwind-50og</guid>
      <description>&lt;p&gt;I've been so focused on my work as a backend dev for the last couple years that I hadn't taken the time to explore the latest and greatests of the frontend ecosystem. Over the holidays, I was finally inspired to dive into &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; and &lt;a href="https://tailwindcss.com/"&gt;Tailwind CSS&lt;/a&gt; and I'm really glad I did!&lt;/p&gt;

&lt;p&gt;One of the mini projects I made as practice is this Random Inspiration Generator. I hope it can help you find some inspiration for the new year! &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Hkly/embed/dypewKG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The React app itself here is very simple and minimal, where I had the most fun with this app was learning about Tailwind CSS. &lt;/p&gt;

&lt;p&gt;Tailwind CSS is a CSS framework with a ton of utility classes that allows you to style your app right in the markup. You can also use it to compose custom styles in CSS. &lt;/p&gt;

&lt;p&gt;I remember when I first looked at Tailwind, I was immediately intimidated by the copious amounts of utility classes. I couldn't wrap my brain around how I was supposed to know what classes existed and what classes to use, but once I broke the seal and dove into it, it became pretty intuitive and the docs are well written. I was able to style this mini inspiration app in just minutes! Okay, maybe a bit longer cause I was going back and forth to the docs, but the important part was I didn't have to spend any time coming up with my own class or selector names or organize my CSS or do any pixel pushing. It was really easy to come up with a polished look with just their built-in utility classes, I didn't have to write any custom CSS, but I like that I can if I needed to. I am definitely sold on Tailwind now and will be using it for my personal projects.&lt;/p&gt;

&lt;p&gt;For React, I, of course, started with the classic to-do app to learn some of the basic functionality. At first, thinking in small components was a bit of a challenge. I wasn't sure how to capture or propagate certain events while also encapsulating things within a component. But after learning about passing functions in props and using React Hooks, I started really enjoying the ease and simplicity of React. In fact, using React Hooks and passing functions as props allowed me to make my functions so short and organize my code in a way that I almost felt like I was writing Ruby and Rails code. Now I can't imagine not thinking in components, I can't imagine not using React and organizing my Javascript in any other way. I talked my non-web developer partner's ear off about how awesome React is over dinner and she told me I was in NRE (new relationship energy) with React. I think I am in love with React. 😍&lt;/p&gt;

&lt;p&gt;I'm used to focusing more on the code that I need for my job, but I am glad I tried something new this year. I am really looking forward to diving deeper and building more with React and Tailwind. I hope this inspires you to try something new too, and don't forget, open yourself to the impression left by thousands of butterflies. 🦋 Happy New Year y'all!&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>react</category>
      <category>tailwindcss</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Something out of Nothing: Null Object Pattern</title>
      <dc:creator>hkly</dc:creator>
      <pubDate>Mon, 13 Jul 2020 22:58:50 +0000</pubDate>
      <link>https://dev.to/hkly/something-out-of-nothing-null-object-pattern-3clm</link>
      <guid>https://dev.to/hkly/something-out-of-nothing-null-object-pattern-3clm</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://blog.beezwax.net/2020/07/13/something-out-of-nothing-null-object-pattern/"&gt;Beezwax.net&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;What is nothing? &lt;code&gt;nil&lt;/code&gt;? &lt;code&gt;null&lt;/code&gt;? &lt;code&gt;undefined&lt;/code&gt;? A vast void of emptiness that fills your soul with dread? Oh sorry, that's just my stomach. &lt;/p&gt;

&lt;p&gt;We often think of nothing as... well, nothing. It's when something doesn't exist and therefore cannot be interacted with. So in our code, we try account for having nothing. No &lt;code&gt;User&lt;/code&gt;? No problem.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;display_name&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;present?&lt;/span&gt;
    &lt;span class="vi"&gt;@user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;titlecase&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="s2"&gt;"Guest User"&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Fixed it with a conditional. Right...?&lt;/p&gt;

&lt;p&gt;But what happens when you want something else from the &lt;code&gt;User&lt;/code&gt; elsewhere? Use another conditional?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;avatar&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;present?&lt;/span&gt;
    &lt;span class="vi"&gt;@user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;avatar&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="n"&gt;default_avatar&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Technically it would solve your problem for now, but soon there will a bunch of &lt;code&gt;if&lt;/code&gt; statements cluttering your code when all you really want to do is simply call a method.&lt;/p&gt;

&lt;h4&gt;
  
  
  Here's where the Null Object Pattern can come in handy.
&lt;/h4&gt;

&lt;p&gt;What if instead of nothing, you had a something. Something that responded to the API of your object. That something would be the "null object"-- It is an object that represents when you have no object, kind of like a placeholder.&lt;/p&gt;

&lt;p&gt;Instead of having to check whether or not you have a &lt;code&gt;User&lt;/code&gt; object, you can ensure you always have something that will respond to your method calls by providing a null object that responds to the API of your object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GuestUser&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;
    &lt;span class="s2"&gt;"Guest User"&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;avatar&lt;/span&gt;
    &lt;span class="n"&gt;default_avatar&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you can use this &lt;code&gt;GuestUser&lt;/code&gt; whenever you don't have a &lt;code&gt;User&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;GuestUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="vi"&gt;@user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;display_name&lt;/span&gt;
  &lt;span class="vi"&gt;@user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;titlecase&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;avatar&lt;/span&gt;
  &lt;span class="vi"&gt;@user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;avatar&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see in the above example, I've injected the &lt;code&gt;GuestUser&lt;/code&gt; in as a default parameter in the constructor. Now if a &lt;code&gt;User&lt;/code&gt; isn't passed in, the code will use the &lt;code&gt;GuestUser&lt;/code&gt;, and no more need for additional conditionals!&lt;/p&gt;

&lt;p&gt;To the keen eye, you'll notice that this Null Object Pattern is actually an example of Composition over Inheritance! Check out &lt;a href="https://blog.beezwax.net/2020/06/29/composition-over-inheritance-with-javascript-examples/"&gt;this post on Composition over Inheritance&lt;/a&gt; if you'd like to learn more.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The code examples are in Ruby, but the concept can be applied to any Object Oriented programming.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Cover photo by &lt;a href="https://unsplash.com/@mischievous_penguins"&gt;Casey Horner&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>beginners</category>
      <category>oop</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Ruby's Safe Navigation Operator `&amp;.` and is it a Code Smell?</title>
      <dc:creator>hkly</dc:creator>
      <pubDate>Mon, 06 Jul 2020 18:34:47 +0000</pubDate>
      <link>https://dev.to/hkly/ruby-s-safe-navigation-operator-and-is-it-a-code-smell-4hd9</link>
      <guid>https://dev.to/hkly/ruby-s-safe-navigation-operator-and-is-it-a-code-smell-4hd9</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://blog.beezwax.net/2020/07/08/rubys-safe-navigation-operator-and-is-it-a-code-smell" rel="noopener noreferrer"&gt;Beezwax.net&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  What is &lt;code&gt;&amp;amp;.&lt;/code&gt;?
&lt;/h1&gt;

&lt;p&gt;Ruby devs are probably all too familiar with seeing this error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NoMethodError (undefined method `foo' for nil:NilClass)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you're not familiar with this error, you can check out Ben's post on it: &lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/ben" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1%2Ff451a206-11c8-4e3d-8936-143d0a7e65bb.png" alt="ben"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/ben/nomethoderror-undefined-method-for-nil-nilclass-explained-422b" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;NoMethodError: undefined method for nil:NilClass... Explained&lt;/h2&gt;
      &lt;h3&gt;Ben Halpern ・ Jul 2 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#rails&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#ruby&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#errorexplained&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;Most of the time, the error is probably due to a typo, but every now and then we end up having to do something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;defined?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt;
&lt;span class="c1"&gt;# returns nil if bar is nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you're on Rails, or are using ActiveSupport, you can use &lt;code&gt;present?&lt;/code&gt; or &lt;code&gt;try()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;present?&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt;
&lt;span class="c1"&gt;# returns false if bar is nil&lt;/span&gt;

&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;try&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:foo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# returns nil if bar is nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In Ruby 2.3.0, they introduced the safe navigation operator &lt;code&gt;&amp;amp;.&lt;/code&gt; which returns &lt;code&gt;nil&lt;/code&gt; when called on a &lt;code&gt;nil&lt;/code&gt; object, like so:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt;
&lt;span class="c1"&gt;# returns nil if bar is nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This can be pretty handy when you're not in Rails-land or just want some compact code. &lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;code&gt;&amp;amp;.&lt;/code&gt; vs &lt;code&gt;.try()&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;So other than the number of characters, what's the difference between ActiveSupport's &lt;code&gt;try()&lt;/code&gt; and the Ruby safe navigation operator &lt;code&gt;&amp;amp;.&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;amp;.&lt;/code&gt; will only return &lt;code&gt;nil&lt;/code&gt; if called on a &lt;code&gt;nil&lt;/code&gt; object. Calling &lt;code&gt;&amp;amp;.&lt;/code&gt; will raise a &lt;code&gt;NoMethodError&lt;/code&gt; if it is called on a non-&lt;code&gt;nil&lt;/code&gt; object that doesn't implement the method. However, &lt;code&gt;try()&lt;/code&gt; will just return &lt;code&gt;nil&lt;/code&gt; if called on anything that doesn't implement the method. (Note: &lt;code&gt;try!()&lt;/code&gt; works just like &lt;code&gt;&amp;amp;.&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'a'&lt;/span&gt;

&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt;
&lt;span class="c1"&gt;# returns NoMethodError (undefined method `foo' for "a":String)&lt;/span&gt;

&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;try&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:foo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#returns nil&lt;/span&gt;

&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;try!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:foo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# returns NoMethodError (undefined method `foo' for "a":String)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This also means that &lt;code&gt;&amp;amp;.&lt;/code&gt; will return &lt;code&gt;NoMethodError&lt;/code&gt; if called on &lt;code&gt;false&lt;/code&gt;, whereas doing a presence check would return &lt;code&gt;false&lt;/code&gt; before attempting to call the method. I'm not sure when this scenario would come up, but it is good to be aware of.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt; 

&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt;
&lt;span class="c1"&gt;# returns NoMethodError (undefined method `foo' for false:FalseClass)&lt;/span&gt;

&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;try&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:foo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#returns nil&lt;/span&gt;

&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;present?&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt;
&lt;span class="c1"&gt;# returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h1&gt;
  
  
  Is this a code smell?
&lt;/h1&gt;

&lt;p&gt;The safe navigator isn't inherently bad. In fact if you have something like this in your code &lt;code&gt;foo &amp;amp;&amp;amp; foo.bar&lt;/code&gt; Rubocop will admonish you for not using safe navigation.&lt;/p&gt;

&lt;p&gt;However, using &lt;code&gt;&amp;amp;.&lt;/code&gt; too often in your code is probably something to avoid. Relying on safe navigation encourages the bad habit of passing around &lt;code&gt;nil&lt;/code&gt;s, it can make bugs harder to find, and personally I find it can make code harder to read. &lt;/p&gt;

&lt;p&gt;For example, I had this piece of code:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;empty?&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pluck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:unicorns_count&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;zero?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;At first it seems pretty innocuous, I was getting a &lt;code&gt;NoMethodError (undefined method 'zero?' for nil:NilClass)&lt;/code&gt;, the fastest thing to do was just toss the safe navigator on there and move on. However, if I left it that way, I'd just run into the error again if I tried calling another method on the results of &lt;code&gt;mean()&lt;/code&gt; somewhere else in my code. Does that mean going around tagging on safe navigators everywhere I called &lt;code&gt;mean()&lt;/code&gt;? No way! The answer was to look at why a method called &lt;code&gt;mean()&lt;/code&gt; was returning &lt;code&gt;nil&lt;/code&gt; to begin with and refactor the method.  &lt;/p&gt;

&lt;p&gt;The safe navigation operator should only be used when &lt;code&gt;nil&lt;/code&gt; is an acceptable result, but more often than not, you don't want to be returning or passing &lt;code&gt;nil&lt;/code&gt; anyway. If you're leaning on &lt;code&gt;&amp;amp;.&lt;/code&gt; too often or you find yourself with code that looks something like:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;potatoes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;baz&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;qux&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It's time to take a closer look at refactoring your code. The 'Null Object Pattern` could be one potential solution (and potentially a future post for me to write🤔).&lt;/p&gt;



&lt;p&gt;I wrote the future post!&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/hkly" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2990%2Fi6svcX0m.jpg" alt="hkly"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/hkly/something-out-of-nothing-null-object-pattern-3clm" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Something out of Nothing: Null Object Pattern&lt;/h2&gt;
      &lt;h3&gt;hkly ・ Jul 13 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#ruby&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#oop&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Cover photo by &lt;a href="https://unsplash.com/@lucabravo" rel="noopener noreferrer"&gt;https://unsplash.com/@lucabravo&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>codesmells</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Running Local NPM Executables</title>
      <dc:creator>hkly</dc:creator>
      <pubDate>Thu, 28 Sep 2017 19:04:47 +0000</pubDate>
      <link>https://dev.to/hkly/running-local-npm-executables-cle</link>
      <guid>https://dev.to/hkly/running-local-npm-executables-cle</guid>
      <description>&lt;p&gt;Typically, npm command line executables are installed globally so you can run it from whatever project on your machine. However, sometimes you'll want to run a locally installed package. Here's how!&lt;/p&gt;

&lt;p&gt;When npm packages with executables are installed locally, they are linked to  &lt;code&gt;./node_modules/.bin&lt;/code&gt; within your project. To invoke them, you would have to enter the entire path pointing to the package name.&lt;/p&gt;

&lt;p&gt;For example, if you've locally installed &lt;code&gt;gulp&lt;/code&gt; for a single project, it would look something like this to invoke it from the project directory: &lt;code&gt;./node_modules/.bin/gulp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To make life easier, you can add this bit of script to your &lt;code&gt;.bashrc&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm-run&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="si"&gt;$(&lt;/span&gt;npm bin&lt;span class="si"&gt;)&lt;/span&gt;/&lt;span class="nv"&gt;$*&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What's happening here is &lt;code&gt;npm bin&lt;/code&gt; returns the path of where your executables are, and then the package name you want to invoke is inserted where the &lt;code&gt;$*&lt;/code&gt; are.&lt;/p&gt;

&lt;p&gt;So now, to run &lt;code&gt;gulp&lt;/code&gt; all you have to do is &lt;code&gt;npm-run gulp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can even define the function with a shorter name instead of &lt;code&gt;npm-run&lt;/code&gt;, like &lt;code&gt;nr&lt;/code&gt;, or whatever your heart desires :)&lt;/p&gt;

&lt;p&gt;Easy as pie!&lt;/p&gt;

</description>
      <category>npm</category>
      <category>javascript</category>
      <category>node</category>
      <category>bash</category>
    </item>
  </channel>
</rss>
