<?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: Parvez M Robin</title>
    <description>The latest articles on DEV Community by Parvez M Robin (@parvezmrobin).</description>
    <link>https://dev.to/parvezmrobin</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%2F310247%2F8bfda86a-c440-48aa-b294-a9a1e8392b2b.jpg</url>
      <title>DEV Community: Parvez M Robin</title>
      <link>https://dev.to/parvezmrobin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/parvezmrobin"/>
    <language>en</language>
    <item>
      <title>13 reasons why you should not use Perl</title>
      <dc:creator>Parvez M Robin</dc:creator>
      <pubDate>Thu, 21 Oct 2021 20:15:33 +0000</pubDate>
      <link>https://dev.to/parvezmrobin/13-reasons-why-you-should-not-use-perl-20d5</link>
      <guid>https://dev.to/parvezmrobin/13-reasons-why-you-should-not-use-perl-20d5</guid>
      <description>&lt;p&gt;Currently, I am conducting a natural language processing course. As part of the curriculum, I need to learn and code in Perl. I was exited! I was enthusiastic! However, the verb is "WAS". I am neither exited nor enthusiastic any more. I already have experience in C, CPP, C#, Java, Golang, Python, JavaScript, TypeScript and Bash. Among this versatile experience, Perl is now my second most hated language after Bash. &lt;em&gt;Let me tell you why&lt;/em&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Weird variable access&lt;/strong&gt;: I have worked with typed language where I need to tell the type. I have worked with weakly typed language where the language knows which is which. Then comes Perl. It is weakly typed. But, I need to prefix a variable by either &lt;code&gt;$&lt;/code&gt; or &lt;code&gt;@&lt;/code&gt; or &lt;code&gt;%&lt;/code&gt; to tell Perl about the type of variable. And I need to do it every time I access the variable. Even more - the prefix changes time to time based on the usage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Too much implicit code&lt;/strong&gt;: Remember, explicit is always better than implicit. But, Perl works the opposite way. Consider the following snippet.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;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;print&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;p&gt;What this does is reads from the input stream in &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; this command, stores it in a variable named &lt;code&gt;$_&lt;/code&gt;, then prints that variable. Of course you can assign and use your own variable but Perl developers seem to prefer this. Well, I don't.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lacking readability&lt;/strong&gt;: Continuing from the previous example, when someone sees that snippet, it is literally hard to get what it is doing. At least, it was hard for me. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;No clear parameter list&lt;/strong&gt;: While declaring a function (called subroutine in Perl), it does not specify the parameter list. You will always pass a list of arguments and the function need to extract them from an array. The end product is too much boiler-plating with too less readability.&lt;br&gt;
This is what you will do, if you need to retrieve 3 parameters.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;func1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="sr"&gt;//&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="nv"&gt;something&lt;/span&gt; &lt;span class="nv"&gt;with&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;variables&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;func1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Weirdly passing arrays to function&lt;/strong&gt;: When you pass an array to a perl function, it flattens everything. Consider the following code.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;func1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nb"&gt;scalar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="nv"&gt;_&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;@a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;@b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;func1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;@b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The &lt;code&gt;scalar&lt;/code&gt; function returns the length of an array and the &lt;code&gt;@_&lt;/code&gt; variable holds the arguments as an array. So, &lt;code&gt;scalar(@_)&lt;/code&gt; will give us the number of arguments. What do you think the output is? &lt;code&gt;2&lt;/code&gt;? It should be. But, it's perl and the output is &lt;code&gt;6&lt;/code&gt;.&lt;br&gt;
If you want to pass an array as an array, you need to make a reference of the array, pass the reference and de-reference it inside the function. Hell of a job for such a simple task!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Weirder passing hash/map to function&lt;/strong&gt;: Okay. When we pass something to a perl function, it flattens everything and makes a single array. What happens to hashes/maps? Well! It makes that an array too. And that array contains all the keys and values; in a single place. Consider the following code.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;func1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nb"&gt;join&lt;/span&gt; &lt;span class="p"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;, &lt;/span&gt;&lt;span class="p"&gt;',&lt;/span&gt; &lt;span class="nv"&gt;@_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;%f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;one&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;two&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;func&lt;/span&gt; &lt;span class="nv"&gt;%f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;What do you think the former code prints? My guess was it will print the keys of the map. At the worst case, it will print the values instead. Alas! The actual worst case worse than what I anticipated. It prints both keys and values. So, the output is &lt;code&gt;one, 1, two, 2&lt;/code&gt;. And it becomes a mess when you want to reconstruct the map.&lt;br&gt;
The mess gets messier if you call the function like &lt;code&gt;func1 %f, three, 3&lt;/code&gt;. How will you know what came from where?&lt;/p&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cryptic RegEx handling&lt;/strong&gt;: When you do a regular expression match, it automatically assigns some variables like &lt;code&gt;$&amp;amp;&lt;/code&gt;, &lt;code&gt;$`&lt;/code&gt;, &lt;code&gt;$'&lt;/code&gt; etc. They are useful when you know them to be honest. But, when you just read the code, specially when you are from another background, it looks like a mess.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Less Searchability&lt;/strong&gt;: Consider the previous point. You are reading a perl program. You suddenly found use of undeclared variables like &lt;code&gt;$&amp;amp;&lt;/code&gt; or &lt;code&gt;$'&lt;/code&gt;. So, you googled about it - &lt;em&gt;"what does $' means in perl"&lt;/em&gt;. Alas! while you search something on the search engines, they generally stripes out spaces and punctuation. You will still have relevant results. But, they won't be as great as if you search - &lt;em&gt;"what does dir mean in python"&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pathetic debugging support&lt;/strong&gt;: The debugging support for perl is in a word pathetic. It only supports some basic commands and the error messages are cryptic. Once you are stuck in somewhere, you are DONE!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Too much implicit error handling&lt;/strong&gt;: While the shown error messages are cryptic, there are a lot of errors that are not shown at all. Say, we have an array &lt;code&gt;@a&lt;/code&gt; and we want to print it. Now, mistakenly we have typed &lt;code&gt;print $a&lt;/code&gt;. It will just print nothing just like if the array was empty. In my opinion it either should through an error or print the memory address of &lt;code&gt;@a&lt;/code&gt;. It does nothing. And you will never know that you have an error there.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Inconsistent behavior&lt;/strong&gt;: Say, we have a function like this&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;one&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="s1"&gt;two&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;p&gt;Now we define two maps like the following&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;%m1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;one&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;%m2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;one&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;%m1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;%m2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;It will print &lt;code&gt;one1&lt;/code&gt; and &lt;code&gt;1two&lt;/code&gt;. Can you make any sense of it? Well, I could not for a while. Turns out if your map's value coincides with one of the functions, it will call that function and use the function's return value as the map's value. But, it will not do such if your map's key coincides with a function.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Poor IDE support&lt;/strong&gt;: So far I have not seen any perl IDE that satisfies me. You can add plugin to VS Code or JetBrains IDEs to support perl. But, they are buggy and are not feature-rich.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;I just hate it&lt;/strong&gt;: This is the full and final reason. And, I guess, this is sufficient reason to hate a language that I just hate it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;John Lennon dreamed of a world without religion. I dream of a world without perl.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>perl</category>
      <category>nlp</category>
      <category>regex</category>
    </item>
    <item>
      <title>What is .dockerignore and why you need it</title>
      <dc:creator>Parvez M Robin</dc:creator>
      <pubDate>Wed, 13 Oct 2021 16:35:12 +0000</pubDate>
      <link>https://dev.to/parvezmrobin/what-is-dockerignore-and-why-you-need-it-1n3m</link>
      <guid>https://dev.to/parvezmrobin/what-is-dockerignore-and-why-you-need-it-1n3m</guid>
      <description>&lt;p&gt;Yesterday, I was trying to replicate a tool from a conference paper. Unfortunately, it is using python 2. I wish one day researchers will know python 2 is dead. Anyway, I dockerized it, built it, ran it. It went fine. Today, I came back to my lab. Tried to build it again. LACKADAY! The build took more than 10 minutes. It kept showing the following message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Preparing build context archive...
&lt;span class="o"&gt;[==================================================&amp;gt;]&lt;/span&gt;79/79 files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, I did what a computer scientist should do — Google. And I found a gem — &lt;code&gt;.dockerignore&lt;/code&gt;. Before jumping into detail. Let me share what was the actual problem in my case. Before building a docker image, the docker CLI compresses all the files in the current directory and sends them to the docker daemon. These files are called the &lt;strong&gt;build context&lt;/strong&gt;. In your &lt;code&gt;Dockerfile&lt;/code&gt; you can only refer to the files/directories from the build context. The scripts I ran yesterday downloaded some files having a size of nearly 10 GB. Hence, when I was building the docker image today, it was taking forever.&lt;/p&gt;

&lt;p&gt;There comes &lt;code&gt;.dockerignore&lt;/code&gt; for the rescue. All the heavy files were inside two directories — &lt;code&gt;data&lt;/code&gt;, and &lt;code&gt;embeddings&lt;/code&gt;. So, I created a file in the project named &lt;code&gt;.dockerignore&lt;/code&gt; and put the following content there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data/
embeddings/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bingo! The build time was reduced from 10 minutes to 10 seconds.&lt;/p&gt;




&lt;p&gt;However, how could this be useful for your particular case? If you are a modern-day developer, surely you are familiar with dependencies. Could be &lt;code&gt;npm&lt;/code&gt;, &lt;code&gt;yarn&lt;/code&gt;, &lt;code&gt;composer&lt;/code&gt;, &lt;code&gt;nuget&lt;/code&gt;, &lt;code&gt;gradle&lt;/code&gt;, &lt;code&gt;gem&lt;/code&gt;, &lt;code&gt;pip&lt;/code&gt;, &lt;code&gt;conda&lt;/code&gt;, &lt;code&gt;cargo&lt;/code&gt;, &lt;code&gt;dep&lt;/code&gt;, or anything else. But there is definitely one. Now, for example, you are using &lt;code&gt;npm&lt;/code&gt;, in most cases, your &lt;code&gt;Dockerfile&lt;/code&gt; contains the following line —&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;RUN &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, you are installing your dependencies &lt;em&gt;inside your image&lt;/em&gt;. Now, if you have a &lt;code&gt;node_modules&lt;/code&gt; directory outside your image (i.e., in your actual machine), that is not actually needed. However, by default, it will be added to the build context with the weight of a black hole and make the build process slow. However, if you put the &lt;code&gt;node_modules&lt;/code&gt; directory in the &lt;code&gt;.dockerignore&lt;/code&gt;, it will have no impact on the build process. The same goes for any other dependency management tools.&lt;/p&gt;

&lt;p&gt;I Hope, from now on, your docker builds will be a little bit faster, if not gigantic.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>container</category>
      <category>devops</category>
      <category>buildcontext</category>
    </item>
  </channel>
</rss>
