<?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: Shakil Ahmed</title>
    <description>The latest articles on DEV Community by Shakil Ahmed (@shakil).</description>
    <link>https://dev.to/shakil</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%2F116871%2Ff704b4d1-2c76-4ac8-9dac-159eddf4be9e.jpeg</url>
      <title>DEV Community: Shakil Ahmed</title>
      <link>https://dev.to/shakil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shakil"/>
    <language>en</language>
    <item>
      <title>Understanding TypeScript Decorators</title>
      <dc:creator>Shakil Ahmed</dc:creator>
      <pubDate>Fri, 16 Apr 2021 17:49:53 +0000</pubDate>
      <link>https://dev.to/shakil/understanding-typescript-decorators-54jj</link>
      <guid>https://dev.to/shakil/understanding-typescript-decorators-54jj</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1599256630445-67b5772b1204%3Fcrop%3Dentropy%26cs%3Dtinysrgb%26fit%3Dmax%26fm%3Djpg%26ixid%3DMnwxMTc3M3wwfDF8c2VhcmNofDh8fHdyZW5jaHxlbnwwfHx8fDE2MTg1OTM0MDM%26ixlib%3Drb-1.2.1%26q%3D80%26w%3D2000" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1599256630445-67b5772b1204%3Fcrop%3Dentropy%26cs%3Dtinysrgb%26fit%3Dmax%26fm%3Djpg%26ixid%3DMnwxMTc3M3wwfDF8c2VhcmNofDh8fHdyZW5jaHxlbnwwfHx8fDE2MTg1OTM0MDM%26ixlib%3Drb-1.2.1%26q%3D80%26w%3D2000" alt="Understanding TypeScript Decorators"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Decorators are used to modify classes and its members (methods, properties).&lt;br&gt;&lt;br&gt;
The question may be, &lt;strong&gt;why do we need decorators to change those things? Why not directly change in the declarations?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Directly changing is not scalable. If you need the same changes in 100 classes, you have to write it 100 times. Using decorators, you write it once and apply it as many times as you want.&lt;/p&gt;

&lt;p&gt;Decorators give you a central point of change which easier to work with. Frameworks like &lt;code&gt;NestJS&lt;/code&gt;, &lt;code&gt;Angular&lt;/code&gt; use decorators extensively.&lt;/p&gt;

&lt;p&gt;In TypeScript, you can decorate the following things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;class&lt;/li&gt;
&lt;li&gt;method&lt;/li&gt;
&lt;li&gt;property&lt;/li&gt;
&lt;li&gt;accessor&lt;/li&gt;
&lt;li&gt;parameter&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Decorators are a TypeScript feature and are not officially included in JavaScript yet. However, they are likely to be added in the future (Currently in stage 2).&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Class decorator
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The following decorator makes any class more Funky&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;makeFunky&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nf"&gt;funkIt&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Get The Funk Outta My Face&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;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="nd"&gt;makeFunky&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;wheels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pause&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;running&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;car&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;Car&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;funkIt&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;// logs: Get The Funk Outta My Face&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Decorators are just functions, &lt;code&gt;makeFunky&lt;/code&gt; is the decorator above. &lt;code&gt;makeFunky&lt;/code&gt; gets the class &lt;code&gt;Car&lt;/code&gt; it's applied to as a parameter. It returns a new class which is just a modified version of the original class.&lt;/p&gt;

&lt;p&gt;Decorators are called when the class is declared—not when an object is instantiated.&lt;/p&gt;
&lt;h3&gt;
  
  
  Method decorator
&lt;/h3&gt;

&lt;p&gt;Decorators applied to a method gets the following parameters&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;target&lt;/strong&gt; : for static methods, &lt;code&gt;target&lt;/code&gt; is the constructor function of the class. For an instance method, &lt;code&gt;target&lt;/code&gt; is the prototype of the class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;propertyKey&lt;/strong&gt; : The name of the method.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;descriptor&lt;/strong&gt; : The Property Descriptor for the method
&lt;/li&gt;
&lt;/ul&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;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;propertyKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;descriptor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropertyDescriptor&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;originalMethod&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;descriptor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
    &lt;span class="nx"&gt;descriptor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;arguments are &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arguments&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;originalMethod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&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="s2"&gt;`result is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;result&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;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Calculator&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;log&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;number&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;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&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;calc&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;Calculator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nx"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="cm"&gt;/*
[LOG]: "arguments are ",  {
  "0": 10,
  "1": 20
} 
[LOG]: "result is 30" 
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Property decorator
&lt;/h3&gt;

&lt;p&gt;Similar to method decorator. Gets the same parameters &lt;code&gt;target&lt;/code&gt;, &lt;code&gt;propertyKey&lt;/code&gt;, and &lt;code&gt;descriptor&lt;/code&gt; as the method decorators. Its return value is ignored.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;logMutation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;_val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newVal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;new value is &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;newVal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nx"&gt;_val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newVal&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&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="nx"&gt;_val&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;logMutation&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;

    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&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;jack&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;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;jack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;

&lt;span class="cm"&gt;/*
[LOG]: "new value is 20" 
[LOG]: "new value is 40" 
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Accessor and parameter decorators
&lt;/h3&gt;

&lt;p&gt;Accessor decorators are same as method decorators, but they are applied to either the getter or setter method of a single member.&lt;/p&gt;

&lt;p&gt;Parameter decorators are applied on, you got it, parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decorator Factory
&lt;/h2&gt;

&lt;p&gt;A common pattern in decorator usage is calling a function that returns a decorator. Here's the previously mentioned method decorator &lt;code&gt;log&lt;/code&gt; , returned by invoking the function logger&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;functionName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;propertyKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;descriptor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropertyDescriptor&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;originalMethod&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;descriptor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
        &lt;span class="nx"&gt;descriptor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;method name: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;functionName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;arguments are &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arguments&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;originalMethod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&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="s2"&gt;`result is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;result&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;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&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="nx"&gt;log&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Calculator&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;add&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&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;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&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;calc&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;Calculator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nx"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="cm"&gt;/*
[LOG]: "method name: add" 
[LOG]: "arguments are ", {
  "0": 10,
  "1": 20
} 
[LOG]: "result is 30" 
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Decorator in the wild
&lt;/h2&gt;

&lt;p&gt;Some use cases of decorators as being utilized by popular libraries/frameworks.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;NestJS&lt;/strong&gt; uses the class decorator &lt;code&gt;@Controller('pathName')&lt;/code&gt; to define a class as a controller. Decorators associate classes with required metadata and enable Nest to create a routing map (tie requests to the corresponding controllers). It also uses decorators to define modules, injectable instances for its dependency injection system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TypeORM&lt;/strong&gt; uses decorators to define a class as an entity &lt;code&gt;@Entity()&lt;/code&gt;, tagging properties as columns &lt;code&gt;@Column()&lt;/code&gt;, auto-incremented ID etc.&lt;/li&gt;
&lt;li&gt;The NPM package &lt;strong&gt;class-validator&lt;/strong&gt; is used for validating properties in an object (used in validations such as income data, arguments of a function). It has decorators like &lt;code&gt;@IsInt()&lt;/code&gt; &lt;code&gt;@Min(5)&lt;/code&gt; &lt;code&gt;@Max(25)&lt;/code&gt; to set restrictions on a particular field.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Unit testing is more important than you think</title>
      <dc:creator>Shakil Ahmed</dc:creator>
      <pubDate>Sun, 11 Apr 2021 02:23:00 +0000</pubDate>
      <link>https://dev.to/shakil/unit-testing-is-more-important-than-you-think-27a2</link>
      <guid>https://dev.to/shakil/unit-testing-is-more-important-than-you-think-27a2</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FMAOYY2v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/02/1_TOL3mutcAV7gEEnIH0DVmg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FMAOYY2v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/02/1_TOL3mutcAV7gEEnIH0DVmg.png" alt="Unit testing is more important than you think"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The most important benefit unit testing gave me is being able to make changes without fearing things might blow up due to even a small change. The whole process of Software development is dealing with complexity where each new step creates a brand new tangle in the already existing fuck sandwich of a stack.&lt;/p&gt;

&lt;p&gt;For smaller projects, you may get away okay without writing unit tests. But in a decent sized project with more than one developer involved, it's a must if you want to keep your sanity intact.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/MVgLEacpr9KVK172Ne/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/MVgLEacpr9KVK172Ne/giphy.gif" alt="Unit testing is more important than you think"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As engineers, all we do is making things that reduce human effort. So why hurt your brain thinking about whether your current changes will break another feature? leave it to the software to test. Unit testing is testing your function as a small unit of your entire app. Besides making sure your function is working properly, this practice has some beneficial side effects as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Superior error handling&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The difference between a good and bad software is that the former handles errors better. When you write code with tests in mind, you know there will be test cases that provide invalid data or invoke the function with incorrect parameters and expect it to throw certain errors. Having tests in mind will automatically force you to write better code and deal with different types of errors in proper way.&lt;/p&gt;

&lt;p&gt;Another way it helps you handle errors better is you can copy test cases for similar features from open source projects. For example, if your code deals with http requests, you can find the test cases commonly used on network requests and add those to your code. Why reinvent the wheel?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Better reasoning about the software&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Test driven develoment is overall a better strategy of software development in my opinion. Thinking about your code in this approach gives a clearer picture.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>jest</category>
      <category>mocha</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to choose a mechanical keyboard</title>
      <dc:creator>Shakil Ahmed</dc:creator>
      <pubDate>Thu, 25 Mar 2021 10:41:03 +0000</pubDate>
      <link>https://dev.to/shakil/how-to-choose-a-mechanical-keyboard-jg8</link>
      <guid>https://dev.to/shakil/how-to-choose-a-mechanical-keyboard-jg8</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--svq3kRHA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.unsplash.com/photo-1606075014584-5ccf554b50db%3Fcrop%3Dentropy%26cs%3Dtinysrgb%26fit%3Dmax%26fm%3Djpg%26ixid%3DMnwxMTc3M3wwfDF8c2VhcmNofDIyfHxtZWNoYW5pY2FsJTIwa2V5Ym9hcmR8ZW58MHx8fHwxNjE2NjY4NjA2%26ixlib%3Drb-1.2.1%26q%3D80%26w%3D2000" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--svq3kRHA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.unsplash.com/photo-1606075014584-5ccf554b50db%3Fcrop%3Dentropy%26cs%3Dtinysrgb%26fit%3Dmax%26fm%3Djpg%26ixid%3DMnwxMTc3M3wwfDF8c2VhcmNofDIyfHxtZWNoYW5pY2FsJTIwa2V5Ym9hcmR8ZW58MHx8fHwxNjE2NjY4NjA2%26ixlib%3Drb-1.2.1%26q%3D80%26w%3D2000" alt="How to choose a mechanical keyboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mechanical keyboards are fantastic. It's one of the few ideas that were replaced by worse alternatives. Lightweight webpages have been replaced by bloated junks, fast desktop apps have been replaced by chromium wrappers made with electron. Awesome mechanical keyboards have been replaced by subpar rubber dome keyboards. Good thing is, mechanical keyboards are gradually making a comeback. There are more and more enthusiasts out there. Me being one of them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enough with the prelude! Tell me what should I consider while buying a mechanical keyboard.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'm glad you asked. While buying a mechanical keyboard, there are 2 primary things to keep in mind. What &lt;strong&gt;switch type&lt;/strong&gt; do you want and what &lt;strong&gt;keyboard size&lt;/strong&gt; do you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mechanical keyboard switch types
&lt;/h2&gt;

&lt;p&gt;Since switches in a mechanical keyboard are the most important part of the keyboard's typing experience, I'm going to focus on it first.&lt;/p&gt;

&lt;p&gt;Mechanical keyboard switches traditionally come in 3 types; clicky, tacticle, and linear. For easier referencing, they are denoted by certain colors. Clicky ones are called blue switches, tactile ones are called brown switches, and liner ones are called red switches.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blue switches
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7TDoec1y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/03/img-productstage-mxBlue%402x-368x368.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7TDoec1y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/03/img-productstage-mxBlue%402x-368x368.png" alt="How to choose a mechanical keyboard"&gt;&lt;/a&gt;MX Blue switch manufactured by Cherry&lt;/p&gt;

&lt;p&gt;Blue switches are the most satisfying switches. They give a click sound along with the tactile feedback. Many people including me are a fan of the sound.&lt;/p&gt;

&lt;p&gt;However, they are really loud. My mechanical keyboard with blue switches used to keep the whole neighborhood awake until late night. When I typed fast, it vibrated the room with brilliant explosions of light, sound, and energy. The switches were quite satisfying, but the people around me thought otherwise, giving it the nickname ' &lt;strong&gt;the machinegun&lt;/strong&gt;'.&lt;/p&gt;

&lt;p&gt;If there are people around you, don't buy a keyboard with blue switches. Get the blue switches only if you work alone and have decent noise isolation in your room.&lt;/p&gt;

&lt;h3&gt;
  
  
  Red switches
&lt;/h3&gt;

&lt;p&gt;They need less pressure (actuation force) than the blue switches on a keypress. Red switches are linear switches having no tactile or sound feedback at all. Since they need less force for a press, they are popular particularly among gamers and touch typists. These switches are quiet and produce very little noise making them usable in office environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Brown switches
&lt;/h3&gt;

&lt;p&gt;Brown switches are a middle-ground between the loud blue switches and quiet red switches. They provide a tactile feedback without creating much noise. Most typists prefer this switch over the others. I'm currently using a keyboard with brown switches as my daily driver and the experience is pretty good. It's not as great as the blue switches IMO, but there are no complaints from neighbors anymore.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mechanical keyboard size
&lt;/h2&gt;

&lt;p&gt;The keyboards in several form factors, named after how many keys they contain.&lt;/p&gt;

&lt;h3&gt;
  
  
  Full size keyboards
&lt;/h3&gt;

&lt;p&gt;We all have used this keyboard size. One thing to note here is it contains 2 sets of numerical keys. One on the top of alphabets, the other is on the side of the keyboard. If you are someone who inputs numbers a lot, you may find the the extra keyboard on the side quite handy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nKwsJKXg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/03/Full-size-keyboard-form-factor-min.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nKwsJKXg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/03/Full-size-keyboard-form-factor-min.png" alt="How to choose a mechanical keyboard"&gt;&lt;/a&gt;Full size keyboard layout&lt;/p&gt;

&lt;h3&gt;
  
  
  TKL (Tenkeyless) size keyboards
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WibaULoW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/03/IMG_20210213_125745.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WibaULoW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/03/IMG_20210213_125745.jpg" alt="How to choose a mechanical keyboard"&gt;&lt;/a&gt;Redragon Kumara k-552 (TKL layout)&lt;/p&gt;

&lt;p&gt;I don't need the extra number pad found on the full size keyboards. That's why I prefer TKL over the full layout. It's smaller in size without sacrificing any functionality.&lt;/p&gt;

&lt;h3&gt;
  
  
  70%-75% keyboards
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D9eZDB1b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/03/IMG_20210316_111003.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D9eZDB1b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/03/IMG_20210316_111003.jpg" alt="How to choose a mechanical keyboard"&gt;&lt;/a&gt;RK71 keyboard (70% layout)&lt;/p&gt;

&lt;p&gt;They retain only the essential keys. Some non-essential keys may not be present depending on the layout. For example, the above 70% keyboards do not have dedicated function keys. Function keys are accessed by pressing &lt;code&gt;fn + number&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  60% keyboards
&lt;/h3&gt;

&lt;p&gt;This layout is very compact and gaining in popularity lately. I personally don't prefer it since I use the navigation keys like &lt;code&gt;Del&lt;/code&gt;, &lt;code&gt;PgUp&lt;/code&gt;, &lt;code&gt;PgDn&lt;/code&gt; a lot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ph84WDse--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/03/ducky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ph84WDse--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/03/ducky.png" alt="How to choose a mechanical keyboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that you will be able to access all the standard keys that you do not see on the layout by pressing different combinations.&lt;/p&gt;

&lt;p&gt;For more information regarding mechanical keyboards or to participate in discussions, check out this subreddit: &lt;a href="https://www.reddit.com/r/MechanicalKeyboards/"&gt;https://www.reddit.com/r/MechanicalKeyboards/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt; : The information and the lists on this post are in no way exhaustive. I have intentionally left out other not-so-common switch types and layouts.&lt;/p&gt;

</description>
      <category>keyboard</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Focus on one thing for longer</title>
      <dc:creator>Shakil Ahmed</dc:creator>
      <pubDate>Fri, 19 Feb 2021 12:42:47 +0000</pubDate>
      <link>https://dev.to/shakil/focus-on-one-thing-for-longer-25kp</link>
      <guid>https://dev.to/shakil/focus-on-one-thing-for-longer-25kp</guid>
      <description>&lt;p&gt;I read on a book that said “When you desperately want something, the universe conspires to make it happen”. This sentence is about perseverance, not desire. Focusing on something for a long time is a reflection of perseverance.&lt;/p&gt;

&lt;h1&gt;
  
  
  Focused work gives better return
&lt;/h1&gt;

&lt;p&gt;The difference of results between continuous attention and fragmented attention over a period of time is significant. With fragmented attention you will only get a superficial idea of the subject. It takes time for a mind to be submerged into something.&lt;/p&gt;

&lt;h1&gt;
  
  
  Some works are not doable without attention
&lt;/h1&gt;

&lt;p&gt;It’s true you can a lot of work without much attention. Logistical tasks such as filling up a form or making powerpoint presentation of the sales figures do not have to be meditative.&lt;br&gt;
But solving creative problems require intense attention. Works like fixing a complex bug in code, editing a research paper, writing a persuasive business proposal demand time and concentration.&lt;/p&gt;

&lt;h1&gt;
  
  
  Focused work is insightful
&lt;/h1&gt;

&lt;p&gt;Immersing into a task gets us something else other than just getting it done. It provides insights. Insight come from deep concentration, it makes you question the why of things rather than how.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To be light is to lose one’s root. To be restless is to lose one’s mastery.&lt;br&gt;
&lt;cite&gt;— Tao Te Ching&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>productivity</category>
      <category>programming</category>
    </item>
    <item>
      <title>Unit testing is more important than you think</title>
      <dc:creator>Shakil Ahmed</dc:creator>
      <pubDate>Tue, 14 Aug 2018 18:00:00 +0000</pubDate>
      <link>https://dev.to/shakil/unit-testing-is-more-important-than-you-think-k81</link>
      <guid>https://dev.to/shakil/unit-testing-is-more-important-than-you-think-k81</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FMAOYY2v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/02/1_TOL3mutcAV7gEEnIH0DVmg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FMAOYY2v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://shakil.me/content/images/2021/02/1_TOL3mutcAV7gEEnIH0DVmg.png" alt="Unit testing is more important than you think"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The most important benefit unit testing gave me is being able to make changes without fearing things might blow up due to even a small change. The whole process of Software development is dealing with complexity where each new step creates a brand new tangle in the already existing fuck sandwich of a stack.&lt;/p&gt;

&lt;p&gt;For smaller projects, you may get away okay without writing unit tests. But in a decent sized project with more than one developer involved, it's a must if you want to keep your sanity intact.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/MVgLEacpr9KVK172Ne/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/MVgLEacpr9KVK172Ne/giphy.gif" alt="Unit testing is more important than you think"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As engineers, all we do is making things that reduce human effort. So why hurt your brain thinking about whether your current changes will break another feature? leave it to the software to test. Unit testing is testing your function as a small unit of your entire app. Besides making sure your function is working properly, this practice has some beneficial side effects as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Superior error handling&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The difference between a good and bad software is that the former handles errors better. When you write code with tests in mind, you know there will be test cases that provide invalid data or invoke the function with incorrect parameters and expect it to throw certain errors. Having tests in mind will automatically force you to write better code and deal with different types of errors in proper way.&lt;/p&gt;

&lt;p&gt;Another way it helps you handle errors better is you can copy test cases for similar features from open source projects. For example, if your code deals with http requests, you can find the test cases commonly used on network requests and add those to your code. Why reinvent the wheel?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Better reasoning about the software&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Test driven develoment is overall a better strategy of software development in my opinion. Thinking about your code in this approach gives a clearer picture.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>jest</category>
      <category>mocha</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
