<?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: Pankaj Sharma</title>
    <description>The latest articles on DEV Community by Pankaj Sharma (@sharmapankaj2512).</description>
    <link>https://dev.to/sharmapankaj2512</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%2F94049%2Fa4ad0fd4-8752-4b5a-bbd7-392cb9f6bfa4.png</url>
      <title>DEV Community: Pankaj Sharma</title>
      <link>https://dev.to/sharmapankaj2512</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sharmapankaj2512"/>
    <language>en</language>
    <item>
      <title>Continuous Deployments Foster DevOps Culture</title>
      <dc:creator>Pankaj Sharma</dc:creator>
      <pubDate>Mon, 10 Aug 2020 02:44:42 +0000</pubDate>
      <link>https://dev.to/sharmapankaj2512/continuous-deployments-foster-devops-culture-l78</link>
      <guid>https://dev.to/sharmapankaj2512/continuous-deployments-foster-devops-culture-l78</guid>
      <description>&lt;p&gt;DevOps culture is talk of the town now a days. Organizations are pushing their management and employees for faster adoption. The trend is noticeably similar to that of Agile adoption. Sadly, what started as a movement to improve the culture, seems to be heavily misunderstood, much like Agile was, and is being adopted and implemented in a way that would make zero difference. I have this feeling in the guts, that says very soon "DevOps is dead" will be trending.&lt;/p&gt;

&lt;p&gt;As part of the adoption, most organizations now have a DevOps team. Many of them, to support the movement, have renamed operations to DevOps. These newly formed (rather renamed) DevOps teams are still not ready to let go the control over the release process. Likewise, the developers are neither ready nor being prepared for the added responsibilities that comes with the adoption of DevOps culture.&lt;/p&gt;

&lt;p&gt;Organizations are adopting DevOps culture primarily to improve their rate of delivery. In my humble opinion, DevOps culture itself is not a cause but an effect. An effect itself cannot bring any improvement, rather its presence is a sign of improvement. So if DevOps culture if an effect then what is the cause ? Continous Delivery / Continuous Deployment is the cause. Organizations that adopt CD will only be the ones with true DevOps culture.&lt;/p&gt;

&lt;p&gt;Organizations should focus on CD rather than the DevOps hype, to improve their speed of delivery. CD at its core is about improving developer productivity and for a successful CD implementation developers first should to be empowered and then made accountable for the entire release process. &lt;/p&gt;

</description>
      <category>devops</category>
      <category>agile</category>
      <category>productivity</category>
      <category>technology</category>
    </item>
    <item>
      <title>Ad-hoc Polymorphism In Elixir Using defprotocol</title>
      <dc:creator>Pankaj Sharma</dc:creator>
      <pubDate>Sun, 09 Aug 2020 05:58:48 +0000</pubDate>
      <link>https://dev.to/sharmapankaj2512/ad-hoc-polymorphism-in-elixir-using-defprotocol-53ih</link>
      <guid>https://dev.to/sharmapankaj2512/ad-hoc-polymorphism-in-elixir-using-defprotocol-53ih</guid>
      <description>&lt;p&gt;This is a follow up on my previous post on &lt;a href="https://dev.to/sharmapankaj2512/adhoc-polymorphism-in-elixir-2nbl"&gt;Ad-hoc Polymorphism&lt;/a&gt;. I highly recommend reading the previous post first. In this post we will refactor the same code to use &lt;code&gt;defprotocol&lt;/code&gt; construct. At the end of this post you will notice that using &lt;code&gt;defprotocol&lt;/code&gt; results in better encapsulation and fewer lines of code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;defprotocol&lt;/code&gt; is a means to achieving ad-hoc polymorphism. Ad-hoc polymorphism in simple terms is a technique of varying behaviour based on their types. Complex states can be modeled in Elixir using the &lt;code&gt;defstruct&lt;/code&gt; construct. States defined using &lt;code&gt;defstruct&lt;/code&gt; can be used as types for achieving ad-hoc polymorphism.&lt;/p&gt;

&lt;p&gt;Lets use &lt;code&gt;defprotocol&lt;/code&gt; to define a protocol (aka behavior) that we want to vary based on structs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  defprotocol ConnectionHandler do
    def handle(con)
  end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;defimpl&lt;/code&gt; let's us implement different behaviors for protocols defined using the &lt;code&gt;defprotocol&lt;/code&gt; construct, as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  defmodule ConnectionHandler.FirstConnectionHandler do
    defstruct con: nil

    defimpl ConnectionHandler, for: ConnectionHandler.FirstConnectionHandler  do
      def handle(%ConnectionHandler.FirstConnectionHandler{con: con}) do
        "First"
      end
    end
  end

  defmodule ConnectionHandler.SecondConnectionHandler do
    defstruct con: nil

    defimpl ConnectionHandler, for: ConnectionHandler.SecondConnectionHandler  do
      def handle(%ConnectionHandler.SecondConnectionHandler{con: con}) do
        "Second"
      end
    end
  end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Below shown test demonstrates how everything glues together. If you have read the previous post, you might notice that no change has been made to the test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  defmodule Blaze.Test do
  use ExUnit.Case

  defprotocol ConnectionHandler do
    def handle(con)
  end

  defmodule ConnectionHandler.FirstConnectionHandler do
    defstruct con: nil

    defimpl ConnectionHandler, for: ConnectionHandler.FirstConnectionHandler  do
      def handle(%ConnectionHandler.FirstConnectionHandler{con: con}) do
        "First"
      end
    end
  end

  defmodule ConnectionHandler.SecondConnectionHandler do
    defstruct con: nil

    defimpl ConnectionHandler, for: ConnectionHandler.SecondConnectionHandler  do
      def handle(%ConnectionHandler.SecondConnectionHandler{con: con}) do
        "Second"
      end
    end
  end

  test "demonstration of `defprotocol`" do
    alias ConnectionHandler.FirstConnectionHandler
    alias ConnectionHandler.SecondConnectionHandler

    assert ConnectionHandler.handle(%FirstConnectionHandler{con: []}) == "First"
    assert ConnectionHandler.handle(%SecondConnectionHandler{con: []}) == "Second"
  end
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This post demonstrates that in Elixir using &lt;code&gt;defprotocol&lt;/code&gt; for adhoc-polymorphism leads to fewer lines of code and better encapsulation.&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Ad-hoc Polymorphism in Elixir</title>
      <dc:creator>Pankaj Sharma</dc:creator>
      <pubDate>Sat, 08 Aug 2020 16:37:25 +0000</pubDate>
      <link>https://dev.to/sharmapankaj2512/adhoc-polymorphism-in-elixir-2nbl</link>
      <guid>https://dev.to/sharmapankaj2512/adhoc-polymorphism-in-elixir-2nbl</guid>
      <description>&lt;p&gt;&lt;strong&gt;Ad-hoc polymorphism&lt;/strong&gt; is a kind of polymorphism that uses &lt;code&gt;types&lt;/code&gt; and  &lt;code&gt;polymorphic functions&lt;/code&gt; (aka function overloading) to change the function behavior depending on the types of its arguments.&lt;/p&gt;

&lt;p&gt;While &lt;code&gt;behaviour&lt;/code&gt; and &lt;code&gt;defprotocol&lt;/code&gt; are preferred options for achieving polymorphism in Elixir, there is also one more option, probably more simplistic. Ad-hoc polymorphism can be achieved in Elixir using a combination of plain structs, function overloading, pattern matching and destructuring. &lt;/p&gt;

&lt;p&gt;First step is to wrap the state, that needs polymorphic behavior in a struct, as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  defmodule ConnectionHandler.FirstConnectionHandler do
    defstruct con: nil
  end

  defmodule ConnectionHandler.SecondConnectionHandler do
    defstruct con: nil
  end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then create a module which will house the overloaded functions, that would pattern match over the structs that we just created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  defmodule ConnectionHandler do
    alias ConnectionHandler.FirstConnectionHandler
    alias ConnectionHandler.SecondConnectionHandler

    def handle(%FirstConnectionHandler{con: con}) do
      "First"
    end

    def handle(%SecondConnectionHandler{con: con}) do
      "Second"
    end
  end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Below shown simple test case demonstrates how it all glues together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;defmodule ConnectionHandler.Test do
  use ExUnit.Case

  defmodule ConnectionHandler.FirstConnectionHandler do
    defstruct con: nil
  end

  defmodule ConnectionHandler.SecondConnectionHandler do
    defstruct con: nil
  end

  defmodule ConnectionHandler do
    alias ConnectionHandler.FirstConnectionHandler
    alias ConnectionHandler.SecondConnectionHandler

    def handle(%FirstConnectionHandler{con: con}) do
      "First"
    end

    def handle(%SecondConnectionHandler{con: con}) do
      "Second"
    end
  end

  test "ad-hoc polymorphism demonstration" do
    alias ConnectionHandler.FirstConnectionHandler
    alias ConnectionHandler.SecondConnectionHandler

    assert ConnectionHandler.handle(%FirstConnectionHandler{con: []}) == "First"
    assert ConnectionHandler.handle(%SecondConnectionHandler{con: []}) == "Second"
  end
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;While this is a way of achieving polymorphism in Elixir, one might want to consider more idiomatic approach of using &lt;a href="https://elixir-lang.org/getting-started/protocols.html#protocols-and-structs"&gt;defprotocol&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; &lt;a href="https://dev.to/sharmapankaj2512/ad-hoc-polymorphism-in-elixir-using-defprotocol-53ih"&gt;Part 2&lt;/a&gt; of this series demonstrates how using &lt;code&gt;defprotocol&lt;/code&gt; retults in better encapsulation and fewer lines of code.&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>beginners</category>
      <category>polymorphism</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>In a nutshell: Race Conditions</title>
      <dc:creator>Pankaj Sharma</dc:creator>
      <pubDate>Mon, 20 Jul 2020 03:02:35 +0000</pubDate>
      <link>https://dev.to/sharmapankaj2512/in-a-nutshell-race-conditions-fkh</link>
      <guid>https://dev.to/sharmapankaj2512/in-a-nutshell-race-conditions-fkh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Race condition&lt;/strong&gt; is a term commonly used in scenarios where outcome is non-deterministic, as the outcome depends on the order in which relevant events occur. For example, in a concurrent program with non-synchronized threads trying to write to console, the order of console writes is non-deterministic. In short, it is a term used to represent an &lt;strong&gt;non-deterministic outcome&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--McvMFy8e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rky10fyg6ejoavkmlrlm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--McvMFy8e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rky10fyg6ejoavkmlrlm.png" alt="Race Condition"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Races&lt;/strong&gt; are a type of race condition that arise when non-synchronized threads try to access and mutate a memory location.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RwVGQJ9Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y9s3rgihi0qy78xjexrl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RwVGQJ9Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y9s3rgihi0qy78xjexrl.png" alt="Data Races"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>concurrency</category>
      <category>racecondition</category>
      <category>beginners</category>
    </item>
    <item>
      <title>In a nutshell: Monads and Functors</title>
      <dc:creator>Pankaj Sharma</dc:creator>
      <pubDate>Fri, 17 Jul 2020 11:22:21 +0000</pubDate>
      <link>https://dev.to/sharmapankaj2512/in-a-nutshell-monads-and-functors-4936</link>
      <guid>https://dev.to/sharmapankaj2512/in-a-nutshell-monads-and-functors-4936</guid>
      <description>&lt;h4&gt;
  
  
  Functors
&lt;/h4&gt;

&lt;p&gt;Any object that provides a method with following signature is a functor&lt;/p&gt;

&lt;p&gt;&lt;code&gt;map :: (a -&amp;gt; b) -&amp;gt; m a -&amp;gt; m b&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;m&lt;/code&gt; is a container, &lt;code&gt;map&lt;/code&gt; opens up the container and converts type &lt;code&gt;a&lt;/code&gt; to &lt;code&gt;b&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Monads
&lt;/h4&gt;

&lt;p&gt;Any object that provides a method with following signature is a monad&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(flatMap) :: m a -&amp;gt; (a -&amp;gt; m b) -&amp;gt; m b&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;m&lt;/code&gt; is a container, &lt;code&gt;flatMap&lt;/code&gt; opens up the container converts &lt;code&gt;a&lt;/code&gt; to &lt;code&gt;mb&lt;/code&gt; and if in the process multiple &lt;code&gt;mb&lt;/code&gt;'s are created then it flattens them to return a single &lt;code&gt;mb&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>monad</category>
      <category>functor</category>
      <category>categorytheory</category>
      <category>functional</category>
    </item>
    <item>
      <title>Deployment pipeline for a platform with collaborating bounded contexts</title>
      <dc:creator>Pankaj Sharma</dc:creator>
      <pubDate>Thu, 16 Jul 2020 04:44:53 +0000</pubDate>
      <link>https://dev.to/sharmapankaj2512/deployment-pipeline-for-a-platform-with-collaborating-bounded-contexts-1cbc</link>
      <guid>https://dev.to/sharmapankaj2512/deployment-pipeline-for-a-platform-with-collaborating-bounded-contexts-1cbc</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YwqppI24--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a1dtamde4dpnpulr3x3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YwqppI24--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a1dtamde4dpnpulr3x3g.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Deployment Pipeline Best Practices Summarized</title>
      <dc:creator>Pankaj Sharma</dc:creator>
      <pubDate>Wed, 15 Jul 2020 03:28:38 +0000</pubDate>
      <link>https://dev.to/sharmapankaj2512/deployment-pipeline-best-practices-summarized-4ekm</link>
      <guid>https://dev.to/sharmapankaj2512/deployment-pipeline-best-practices-summarized-4ekm</guid>
      <description>&lt;p&gt;Deployment pipeline as defined in the &lt;a href="https://www.goodreads.com/book/show/8686650-continuous-delivery"&gt;Continuous Delivery&lt;/a&gt;, is a process of converting commits into certified releasable artifact. &lt;/p&gt;

&lt;p&gt;As a developer, who loves types, I would rephrase the definition for conciseness as&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DeploymentPipeline :: List&amp;lt;Commit&amp;gt; -&amp;gt; Try&amp;lt;ReleaseableArtifact&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;While working as a consultant, when it comes to deployment pipelines, I have seen same mistakes being repeated across teams. So it is worth reiterating the deployment pipelines guidelines as mentioned in the &lt;a href="https://www.goodreads.com/book/show/8686650-continuous-delivery"&gt;Continuous Delivery&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build your binaries only once&lt;/li&gt;
&lt;li&gt;Binaries should not be environment specific&lt;/li&gt;
&lt;li&gt;Deploy same way to every environment&lt;/li&gt;
&lt;li&gt;Smoke test your deployments&lt;/li&gt;
&lt;li&gt;Deploy into copy of production&lt;/li&gt;
&lt;li&gt;Each change should propagate through the pipeline instantly&lt;/li&gt;
&lt;li&gt;If any part of the pipeline fails stop the pipeline&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I highly recommend &lt;a href="https://www.goodreads.com/book/show/8686650-continuous-delivery"&gt;Continuous Delivery&lt;/a&gt; book that further elaborates on each of these points. &lt;/p&gt;

</description>
      <category>continuousdelivery</category>
      <category>cd</category>
      <category>devops</category>
      <category>deployment</category>
    </item>
    <item>
      <title>Team practices for successful CI</title>
      <dc:creator>Pankaj Sharma</dc:creator>
      <pubDate>Fri, 10 Jul 2020 18:24:14 +0000</pubDate>
      <link>https://dev.to/sharmapankaj2512/team-practices-for-successful-ci-51cm</link>
      <guid>https://dev.to/sharmapankaj2512/team-practices-for-successful-ci-51cm</guid>
      <description>&lt;p&gt;Goal of a successful continuous integration implementation is to prove that software will remain in &lt;strong&gt;working state&lt;/strong&gt; even after the new increment in merged.&lt;/p&gt;

&lt;p&gt;Following practices will help teams get the most out of their CI implementation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;check-in regularly, at least once a day&lt;/li&gt;
&lt;li&gt;don't check-in on a broken build&lt;/li&gt;
&lt;li&gt;run tests locally before committing&lt;/li&gt;
&lt;li&gt;never go home on a broken build&lt;/li&gt;
&lt;li&gt;be prepared to revert a previous version&lt;/li&gt;
&lt;li&gt;time-box fixing before reverting&lt;/li&gt;
&lt;li&gt;fail build for slow tests&lt;/li&gt;
&lt;li&gt;fail build for warnings&lt;/li&gt;
&lt;li&gt;fail build for formatting issues&lt;/li&gt;
&lt;li&gt;fail build for violation of code quality metrics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Continuous-Integration-Improving-Software-Reducing/dp/0321336380"&gt;Continuous Integration Book&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Continuous-Delivery-Deployment-Automation-Addison-Wesley-ebook/dp/B003YMNVC0"&gt;Continuous Delivery Book&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ci</category>
      <category>bestpractices</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
