<?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: Umair</title>
    <description>The latest articles on DEV Community by Umair (@umr55766).</description>
    <link>https://dev.to/umr55766</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%2F170443%2F24fb7e8f-6144-4a36-90db-aa0814775c82.jpg</url>
      <title>DEV Community: Umair</title>
      <link>https://dev.to/umr55766</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/umr55766"/>
    <language>en</language>
    <item>
      <title>Why should we use Lombok's @Builder annotation ?</title>
      <dc:creator>Umair</dc:creator>
      <pubDate>Mon, 26 Jul 2021 19:35:42 +0000</pubDate>
      <link>https://dev.to/umr55766/why-should-we-use-lombok-s-builder-annotation-249n</link>
      <guid>https://dev.to/umr55766/why-should-we-use-lombok-s-builder-annotation-249n</guid>
      <description>&lt;p&gt;Have you also ever looked at the long list of getters and setters methods in an Object class, like this User class (for example)&lt;/p&gt;

&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F43tnb0iip3wxejle1k0p.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F43tnb0iip3wxejle1k0p.png" alt="User class with lots of getters and setters"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and got a gut feeling that all these boilerplates are useless. There must be a better way to achieve similar functionality ?&lt;/p&gt;

&lt;p&gt;Well, we were correct!&lt;/p&gt;

&lt;h4&gt;
  
  
  What to expect out of this article ?
&lt;/h4&gt;

&lt;p&gt;In this blog, We’ll be discussing what Lombok's &lt;a class="mentioned-user" href="https://dev.to/builder"&gt;@builder&lt;/a&gt; annotation is and why we need it in the first place? Bit about how we can use it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why am I writing this ?
&lt;/h4&gt;

&lt;p&gt;This is to set the context for next article. In which I'll be sharing with you a recent learning which we had in our project, of course, related to this Lombok's &lt;a class="mentioned-user" href="https://dev.to/builder"&gt;@builder&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before diving into this annotation, let’s review what Lombok is.&lt;/p&gt;

&lt;h2&gt;
  
  
  What
&lt;/h2&gt;

&lt;p&gt;Recently, I have started working in Java and that’s how I came to know about Legendary Lombok. For those people who haven’t encountered it yet (like me, until recently) - &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://www.projectlombok.org/" rel="noopener noreferrer"&gt;Lombok&lt;/a&gt; is a Java library. Easily integratable with our IDE, build tools. It provides getter, setter, constructors, few other default functions like equals, etc. We just have to use it’s annotations. It works out of the box.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/builder"&gt;@builder&lt;/a&gt; annotation enforces &lt;a href="https://refactoring.guru/design-patterns/builder" rel="noopener noreferrer"&gt;Builder Design Pattern&lt;/a&gt;. It provides APIs to build objects of the annotated class. It also provides an option to convert existing objects into it’s builder, so that we can modify and rebuild it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why
&lt;/h2&gt;

&lt;p&gt;If we have to build object of the User class shown above, (without using Builder) we’ll be doing something like this:&lt;/p&gt;

&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4gtaqu7h0pwxuhqcqult.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4gtaqu7h0pwxuhqcqult.png" alt="Creating a User class object using setters"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is still okaish, we’re just setting each of the properties of the user class object. What's more annoying is that there is a long list of getter and setter methods in the User class. Which are nothing but boilerplates. So kinda frustrating.&lt;/p&gt;

&lt;h2&gt;
  
  
  How
&lt;/h2&gt;

&lt;p&gt;This is where &lt;a class="mentioned-user" href="https://dev.to/builder"&gt;@builder&lt;/a&gt; annotation of the Lombok comes into picture. If we just annotate our User class with &lt;a class="mentioned-user" href="https://dev.to/builder"&gt;@builder&lt;/a&gt; then all the getter setter boilerplates from our User class will be striped out. The Object creation would get simplified something like:&lt;/p&gt;

&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdruujn3tc1t1vjro7dj.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdruujn3tc1t1vjro7dj.png" alt="Creating a User class object using Builder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You see, how intuitive it becomes ? It’s just like assigning properties value and building it.&lt;/p&gt;

&lt;p&gt;So this is how we create User objects from a builder or raw values. But, what if we want to convert an existing object to it’s builder equivalent.&lt;/p&gt;

&lt;p&gt;For that purpose, &lt;a class="mentioned-user" href="https://dev.to/builder"&gt;@builder&lt;/a&gt; provides a configuration parameter toBuilder. This is how we configure and use it:&lt;/p&gt;

&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmac66yordqj2i4no9bxb.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmac66yordqj2i4no9bxb.png" alt="Converting User object to it's Builder using toBuilder()"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's a quick intro about Lombok, &lt;a class="mentioned-user" href="https://dev.to/builder"&gt;@builder&lt;/a&gt; and it's toBuilder.&lt;/p&gt;

&lt;p&gt;Watch out for next article regarding our recent learning experience.&lt;/p&gt;

&lt;p&gt;Just to ignite the curiosity in you, so we we're modifying an object exactly similar to one shown in above example. As a result, instead of updating same object it was behaving bit weirdly. That's how we uncovered an interesting part of this. Which we'll be covering in next article.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://forms.gle/aRQB23pJN4kJtvoN9" rel="noopener noreferrer"&gt;Looking forward to your feedback&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>codequality</category>
    </item>
    <item>
      <title>How to create an automated code cleaner with pre commit hook</title>
      <dc:creator>Umair</dc:creator>
      <pubDate>Wed, 18 Sep 2019 15:59:17 +0000</pubDate>
      <link>https://dev.to/umr55766/how-to-create-an-automated-code-cleaner-with-pre-commit-hook-3j85</link>
      <guid>https://dev.to/umr55766/how-to-create-an-automated-code-cleaner-with-pre-commit-hook-3j85</guid>
      <description>&lt;p&gt;We had a repo with code, some parts of which were not formatted properly. So this is the story of how we kick started our mission to clean-up our codebase, eventually, using git pre-commit hook. Maybe we won’t need these anymore (as nowadays, IDEs have these in-built) but my motto is to demonstrate how we can automate &amp;amp; improve our day to day development process, with no to very little efforts.&lt;/p&gt;

&lt;p&gt;So the other day, I was going through the pull request of my teammate and I noticed that several minor code formatting have been overlooked. Those very ignorable (as per normal human being) so I felt a bit kinda stupid of myself to explain the logic behind my thoughts and comment to fix them. I wish we had a Development Style Guide defined and mutually agreed upon also but unfortunately, we didn’t. Something like this &lt;a href="https://thermondo.github.io/style-guide/"&gt;https://thermondo.github.io/style-guide/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I thought why don’t we automate this whole code formatting process. So for that we need to agree upon a code style format and figure out a way to format in common way.&lt;/p&gt;

&lt;p&gt;Lucky for Python we have a very well-defined PEP-8 &lt;a href="https://www.python.org/dev/peps/pep-0008/"&gt;https://www.python.org/dev/peps/pep-0008/&lt;/a&gt; which I really miss in few other languages. So with this our first checklist was DONE.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://black.readthedocs.io/en/stable/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DSogaKyV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://black.readthedocs.io/en/stable/_static/logo2.png"&gt;&lt;/a&gt; Secondly, we had to figure out a common way to format our code. We discovered this jewel, black - &lt;a href="https://github.com/psf/black"&gt;https://github.com/psf/black&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now the human behaviour come into play, we had everything in place. A style guide and a formatter but sometimes we were not conscious enough to format our code before committing. This part was not in the initial plan, typical example of - why software projects are not delivered on time. Surprises everywhere!&lt;br&gt;
So we took this as a challenge and thought about automating this part too. Maybe integrate it with something that we won’t miss.&lt;/p&gt;

&lt;p&gt;All of us had one thing in common and we can’t miss that - Committing. We were using git as our version control system thus all of us will certainly use git commit. How can we integrate this to commits itself - git pre-commit hook came to our rescue.&lt;/p&gt;

&lt;p&gt;We designed this tiny very simply pre-commit hook to format and verify our code before committing it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;git diff &lt;span class="nt"&gt;--cached&lt;/span&gt; &lt;span class="nt"&gt;--name-only&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s1"&gt;'\.(py)$'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;do
  &lt;/span&gt;black &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="si"&gt;$(&lt;/span&gt;git add &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;done

for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;git diff &lt;span class="nt"&gt;--cached&lt;/span&gt; &lt;span class="nt"&gt;--name-only&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s1"&gt;'\.(py)$'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;do
  &lt;/span&gt;flake8 &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; &lt;span class="nt"&gt;-ne&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"flake8 failed on staged file '&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;'. Please check your code and try again. To check output manually run flake8 &lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;exit &lt;/span&gt;1 &lt;span class="c"&gt;# exit with failure status&lt;/span&gt;
  &lt;span class="k"&gt;fi
&lt;/span&gt;Done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So with this no manual intervention was required. We only needed to committ as usual and it will auto-format the code and verify it - sometimes black fails or something goes wrong, so it’ll fail in verification stage and we’ll need to manually fix it.&lt;/p&gt;

&lt;p&gt;So just for the sake of clarity, in pre-commit hook we’re iterating through the files staged to be committed and black(ening, auto-formatting them) and then again verifying them same way - exit with non-error code just to indicate error occurred. We need to place this in our repo at .git/hooks/pre-commit For this hook to work we need to have black and flake8 pre-installed in our system.&lt;/p&gt;
&lt;h4&gt;
  
  
  Learning:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;We started to not worry about formatting our code.&lt;/li&gt;
&lt;li&gt;We didn’t need to worry about missing a line or two.&lt;/li&gt;
&lt;li&gt;WE WERE CLEANING OUR REPO - best part was unconsciously. If we opened a file after a while, we felt like a magic, when did we format this file ? Awesome!&lt;/li&gt;
&lt;li&gt;We were not bloating the commits with irrelevant changes - by only formatting those files which we were committing anyways. Passive code clean-up drive.&lt;/li&gt;
&lt;li&gt;Lots of developers time were saved, arguing whether &amp;amp; why to have curly braces at the end of line or in the next line.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  References:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;We discussed this pre-commit hook :&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/umr55766/ece111837cfb468211ccacb9e65fb5be"&gt;&lt;/a&gt;&lt;a href="https://gist.github.com/umr55766/ece111837cfb468211ccacb9e65fb5be"&gt;https://gist.github.com/umr55766/ece111837cfb468211ccacb9e65fb5be&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;We used this : The uncompromising Python code formatter &lt;a href="https://black.readthedocs.io/en/stable/"&gt;&lt;/a&gt;&lt;a href="https://black.readthedocs.io/en/stable/"&gt;https://black.readthedocs.io/en/stable/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Tool For Style Guide Enforcement : &lt;a href="https://github.com/pycqa/flake8"&gt;&lt;/a&gt;&lt;a href="https://github.com/pycqa/flake8"&gt;https://github.com/pycqa/flake8&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Pair programming vs Long drive</title>
      <dc:creator>Umair</dc:creator>
      <pubDate>Wed, 18 Sep 2019 15:45:37 +0000</pubDate>
      <link>https://dev.to/umr55766/pair-programming-vs-long-drive-232o</link>
      <guid>https://dev.to/umr55766/pair-programming-vs-long-drive-232o</guid>
      <description>&lt;p&gt;As we want to build products which are maintainable, extensible and scalable in the long run. Usually we do this with the help of a team of solo developers. Let’s see how this can be done more efficiently in a better way with developers working as pairs.&lt;/p&gt;

&lt;p&gt;Recently I went through a Developer Bootcamp focused on Agile methodologies of Extreme programming. Pair programming was one of the focus of my bootcamp. This bootcamp was like an eye opener for me, so I would like to share a few misconceptions which were cleared in the same.&lt;/p&gt;

&lt;p&gt;Before we get into technical stuff of pair programming, I would like to tell you a short story from a real life incident which is analogous to software development.&lt;/p&gt;

&lt;p&gt;One fine Saturday, me and two of my friends decided to go on a long drive. I took my bike and my friends started with their car. Since I was on two wheelers I was able to pierce through the city traffic very quickly, but as soon as I got to the outskirts of the city, my progress was struck, because I have to stop and see the navigation map in short intervals and therefore I cant drive myself beyond a certain speed. Whereas my friends were behind me, stuck in the city traffic, but as soon as they crossed the chaos of city traffic their velocity became quite high and sustainable, as one of them drove and the other navigated.&lt;/p&gt;

&lt;p&gt;Do you see the difference ? Why my friends overtook me in cars, even though I was able to take a good lead in the beginning?&lt;/p&gt;

&lt;p&gt;If you’re wondering how is this related to pair programming, keep reading.&lt;/p&gt;

&lt;p&gt;No alt text provided for this image&lt;br&gt;
So basically, the same thing happens in traditional project development. In kick off phase of any project we just allocate head counts and ask them to start working. At first, everything seems to be smooth,We can see new features being released frequently. Remember how I pierced through the city traffic and took lead ?&lt;/p&gt;

&lt;p&gt;But as the project progresses and things start getting complex ,few small issues start popping up. Code reviewers starts getting too many code review requests and then it becomes bottle-neck.&lt;/p&gt;

&lt;p&gt;What if a person responsible for devops fall sick ? What if I met with an accident ? If something goes wrong (which I hope never to happen) with one of my friends, another can take over. This is called the Bus effect in action.&lt;/p&gt;

&lt;p&gt;So to sum up -&lt;/p&gt;

&lt;p&gt;Pair programming is an agile software development technique in which two programmers work together at one workstation in order to :&lt;/p&gt;

&lt;p&gt;deliver efficient work&lt;br&gt;
write code with fewer bugs&lt;br&gt;
share technical knowledge while developing (thus reducing pain points)&lt;br&gt;
upskills developers interpersonal skills&lt;/p&gt;

&lt;p&gt;Now, few misconceptions which I had :&lt;br&gt;
Why should an experienced person waste time ramping up novice ?&lt;br&gt;
Focus is on building up large pool of redundant assets rather than only on delivering features.&lt;/p&gt;

&lt;p&gt;It’s like carrying Stepney, which would help you when something goes wrong with the main tire. Reducing Bus effect.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Some may feel that they are not able to get into focused mode, since they are supposed to talk while thinking/coding. -&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;They can ask for a time-boxed break to think independently and then come up with data.&lt;/p&gt;

&lt;p&gt;It’s like using first gear in steep ascend, where speed is slow but it elevates you. Don’t expect to drive in same speed/gear throughout the journey.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Some may feel that it takes two asset and double man-hours to accomplish same features&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Reality is code review and the refactor cycle time is saved. It’s not exactly double, it’s way less. And at the same time, quality is way beyond the sum of the parts.&lt;/p&gt;

&lt;p&gt;Four wheelers takes more space than two wheelers but in long journey two wheelers can’t beat them&lt;/p&gt;

&lt;p&gt;No alt text provided for this image&lt;br&gt;
Two wheelers(solo developers) can help in conquering city traffic(starting of big projects). But if we want to go on a comfortable(maintainable), sustainable long(scaleable) journey(product). Four wheelers(pair programming) are go to. It(pair programming) has redundant assets — drivers, tyres, etc (large pool of assets). It(pair programming) has more momentum (one pair can motivate another one). It(pair programming) is fault-tolerant (One pair may catch corner-cases missed by another pair), safer (reduces bus effect)&lt;/p&gt;

&lt;p&gt;Still not convinced ? Cool! Checkout this research paper &lt;a href="https://collaboration.csc.ncsu.edu/laurie/Papers/XPSardinia.PDF"&gt;https://collaboration.csc.ncsu.edu/laurie/Papers/XPSardinia.PDF&lt;/a&gt; and let’s connect!&lt;/p&gt;

&lt;p&gt;Thanks for your time. Let me know your feedbacks.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
