<?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: Raounak Sharma</title>
    <description>The latest articles on DEV Community by Raounak Sharma (@where_i_stuck).</description>
    <link>https://dev.to/where_i_stuck</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%2F118090%2F6f9f2bbd-7f1f-47ed-964d-726ab1665509.jpg</url>
      <title>DEV Community: Raounak Sharma</title>
      <link>https://dev.to/where_i_stuck</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/where_i_stuck"/>
    <language>en</language>
    <item>
      <title>Dependency Injection | Writing loosely coupled code</title>
      <dc:creator>Raounak Sharma</dc:creator>
      <pubDate>Tue, 18 Feb 2020 16:56:50 +0000</pubDate>
      <link>https://dev.to/where_i_stuck/dependency-injection-writing-loosely-coupled-code-2g8i</link>
      <guid>https://dev.to/where_i_stuck/dependency-injection-writing-loosely-coupled-code-2g8i</guid>
      <description>&lt;p&gt;In life, we depend on a lot of things to survive. And object-oriented languages that are used to simulate real-world entities in terms of the objects also have dependencies. They have it in terms of one object depending on others. We say that this object is dependent on others when any change in later will force a change in the previous one.&lt;/p&gt;

&lt;p&gt;One object depends on other means it knows about it. The former one knows the name of the other object, it's properties and it's behavior. We call such objects tightly coupled i.e two objects are tightly coupled if they know a lot about each other and neither of them can't be reused without using the other one. &lt;/p&gt;

&lt;p&gt;Such type of codebase is not good in terms of the reusability of code. One such issue which causes tightly coupled code is referring to other classes directly in methods of a class. This makes the class to work with only that particular class which we have mentioned in the method. We can solve this by &lt;em&gt;dependency injection&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Dependency Injection means we explicitly inject dependencies into the new object we are creating.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Always inject your dependencies and never explicitly mention them inside methods. &lt;br&gt;
Consider the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bill&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;amount&lt;/span&gt;
    &lt;span class="n"&gt;total_price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list_product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;Restaurant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;standard_service_tax&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;total_price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list_product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Return total amount by adding the price of each product&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The problem with this code is that the Bill class object will only respond to amount behavior if there is a Restaurant class present and implements &lt;code&gt;standard_service_tax&lt;/code&gt; behavior. We are not able to reuse this Bill class with another class even though if that has &lt;code&gt;standard_service_tax&lt;/code&gt; behavior implemented.&lt;/p&gt;

&lt;p&gt;The correct code could be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bill&lt;/span&gt;
  &lt;span class="nb"&gt;attr_reader&lt;/span&gt; &lt;span class="ss"&gt;:service&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;service: &lt;/span&gt;&lt;span class="no"&gt;Restraunt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="vi"&gt;@service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;amount&lt;/span&gt;
    &lt;span class="n"&gt;total_price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list_product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;standard_service_tax&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;total_price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list_product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Return total amount by adding the price of each product&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we can pass any object to the constructor of Bill, and the amount will work if they have the &lt;code&gt;standard_service_tax&lt;/code&gt; behavior implemented.&lt;/p&gt;

&lt;p&gt;Summary&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Injecting dependencies will make the class loosely coupled and thus increases it's reusability. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy Coding 🎉&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>oops</category>
      <category>codequality</category>
      <category>cleancode</category>
    </item>
    <item>
      <title>How I got a chance to speak at the International Ruby Conference</title>
      <dc:creator>Raounak Sharma</dc:creator>
      <pubDate>Mon, 12 Aug 2019 16:09:31 +0000</pubDate>
      <link>https://dev.to/where_i_stuck/how-i-got-a-chance-to-speak-at-the-international-ruby-conference-4hh</link>
      <guid>https://dev.to/where_i_stuck/how-i-got-a-chance-to-speak-at-the-international-ruby-conference-4hh</guid>
      <description>&lt;p&gt;I just completed my graduation in computer science and working as a software engineer at OnceHub. I started developing small web apps in early 2017. &lt;/p&gt;

&lt;p&gt;I also have a pro tip which you will find at the end of the blog. :)&lt;/p&gt;

&lt;p&gt;I did some things here and there which helped me in getting selected for 3 international Ruby conferences as a speaker, and I in order to giving back to community here are those things: &lt;/p&gt;

&lt;p&gt;I want to keep it short so that you can read a short paragraph and can have the actual idea without wasting a lot of time.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcwi3vl21epkdtg4xjio3.jpeg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcwi3vl21epkdtg4xjio3.jpeg" alt="My journey"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From my experience, I can say that people at conferences come to listen to developers experiences. When they stuck in a problem how they overcome that. They are not very much into those things which one can learn from blogs like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to use a software&lt;/li&gt;
&lt;li&gt;What new is coming in next feature&lt;/li&gt;
&lt;li&gt;How to make React App&lt;/li&gt;
&lt;li&gt;Best practices while developing Angular app&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may find these talks some where and mostly in local meetups but I think they are not very much interesting. Rather following topics are very interesting:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I got stuck at a point where I need to migrate a big DB withing a night&lt;/li&gt;
&lt;li&gt;I made a CLI application to help a big product. This is my talk :)&lt;/li&gt;
&lt;li&gt;VS talks are very famous. Rails VS Django, Angular VS React and all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok so now lets see how I made it:&lt;/p&gt;




&lt;h1&gt;
  
  
  1. Doing online courses and simultaneously applying for internships
&lt;/h1&gt;

&lt;p&gt;In early 2017 I was doing a lot of online courses, mostly on Angular and Rails on Udemy. If you want to know the courses I did then comment below and I will provide links.&lt;br&gt;
At the same time, I was applying to many internships. You can have an idea from this: I applied to 77 internships from 2017 to mid-2018, and got selected in 5.&lt;/p&gt;

&lt;p&gt;I don't think about they will not select me and many did not select me, but it's ok, I eventually find startups where I can contribute, and once I got the first internship then getting next becomes easy. &lt;/p&gt;

&lt;p&gt;The key is to keep applying and learning. &lt;/p&gt;

&lt;h1&gt;
  
  
  2. While doing internship keep looking for content
&lt;/h1&gt;

&lt;p&gt;This is the time when you will content. While working I stuck in many places. I used to spend 3-4 days on a single problem to get it to work. But during that time I learned how things work. And that is the content. Content for a talk.&lt;/p&gt;

&lt;p&gt;Make a draft of that. And apply to local meetups for a talk. No matter how many rejections you will get, just keep applying. And do try to improve the content after every rejection, if they provide feedback. &lt;br&gt;
One thing to get to know about the quality of your content is to keep attending meetups and if you can afford then conferences as well.&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Apply for the first talk
&lt;/h1&gt;

&lt;p&gt;When I was in Pune doing my internship at Coupa, I made a CLI app to help a big Rails app. It was a big thing from me, so I made a paper from it and applied to a &lt;a href="https://twitter.com/deccanrubyconf" rel="noopener noreferrer"&gt;DeccanRubyConf&lt;/a&gt; 2018, I was first as a backup speaker and one speaker opt out. So I got a chance to speak at my first big Internation Ruby Conference. Here is the &lt;a href="https://www.youtube.com/watch?v=DMg17iak2lU&amp;amp;t=1s" rel="noopener noreferrer"&gt;link&lt;/a&gt; of my talk.&lt;/p&gt;

&lt;p&gt;After that, I spoke at &lt;a href="https://twitter.com/rubyfuza" rel="noopener noreferrer"&gt;RubyFuza 2019&lt;/a&gt; and &lt;a href="https://twitter.com/NairubyKE" rel="noopener noreferrer"&gt;RubyConf Kenya 2019&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;My journey is I tied doing a lot of internships, getting content from them and then applying to lot of conferences and meetups from that content. Eventually, I got a shot and made that work. &lt;/p&gt;

&lt;p&gt;If anyone of you is struggling in this process then connect with me on &lt;a href="https://twitter.com/Raounaksharma" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; and let's see how can I help you, can how we can grow together. &lt;/p&gt;

&lt;p&gt;Happy growing :) 👋&lt;/p&gt;




&lt;p&gt;Know your tool #2: &lt;a href="https://dev.to/where_i_stuck/docker-for-mac--know-your-tools-2-28a7"&gt;Docker&lt;/a&gt;&lt;br&gt;
Know your tool #1: &lt;a href="https://dev.to/where_i_stuck/know-your-tools-vs-code-5ckd"&gt;VS-Code&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>conferences</category>
      <category>personaldevelopment</category>
      <category>learning</category>
    </item>
    <item>
      <title>Docker for Mac | Know your tools #2</title>
      <dc:creator>Raounak Sharma</dc:creator>
      <pubDate>Fri, 01 Mar 2019 06:37:54 +0000</pubDate>
      <link>https://dev.to/where_i_stuck/docker-for-mac--know-your-tools-2-28a7</link>
      <guid>https://dev.to/where_i_stuck/docker-for-mac--know-your-tools-2-28a7</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SzxmAh6U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8kex8622nc3p5je4c9g6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SzxmAh6U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8kex8622nc3p5je4c9g6.png" alt="Docker Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Docker the big beast in microservice and distributed system world. So in my current going internship, I was asked to deploy my Kafka Ruby consumer to staging in a docker container environment. &lt;br&gt;
Seems easy to me according to what I have heard about Docker. But the experience I had is totally different.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is here for you?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The clean and clear knowledge of how Docker works on Mac.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why you need this? you asked&lt;/strong&gt; because you are developing on Mac and the production instance is Ubuntu. Ya both are UNIX based operating system but there is a difference in between them in terms of how Docker run on them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;And if you don't want to do the research by yourself by digging in the official docs of Docker for both environments, then this my sir/madam is the thing you are looking for. And also it will help a lot in debugging because you know what's going on in there.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The difference
&lt;/h2&gt;

&lt;p&gt;If you are new to docker then let's get the floor clean first. There is a thing called container-based solutions. What this approach does is making a bundle of your app's code, its dependencies, environment and sometimes executable. And call that bundle as a container. Now everything the app needs to run properly is there in that bundle or container. From now onwards we will call it a container.&lt;/p&gt;

&lt;p&gt;So now what we need is an operating system kernel to run this application on hardware. Did you get the &lt;strong&gt;hit?&lt;/strong&gt; These are not virtual environment machines over your host machine. No virtual machine, do remember this.&lt;/p&gt;

&lt;p&gt;So what is Docker? &lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt; is just an implementation of this approach. And it is not alone in the market, &lt;a href="https://kubernetes.io/"&gt;Kubernetes&lt;/a&gt; is also doing this.&lt;/p&gt;

&lt;p&gt;Now if you go on the official websites you will see words like &lt;strong&gt;scaling&lt;/strong&gt;, &lt;strong&gt;automatic deployment&lt;/strong&gt;, &lt;strong&gt;better architecture&lt;/strong&gt;, &lt;strong&gt;and all sort of DevOps problem jargons&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Docker does that but those things are right now out of the scope of this blog.&lt;/p&gt;




&lt;h3&gt;
  
  
  Now let's dig, on how it works.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C6lrm1Ad--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gk4od66qmuexrsbplzdp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C6lrm1Ad--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gk4od66qmuexrsbplzdp.jpg" alt="digging deep"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Linux OS (Ubuntu)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I think docker was actually build to work in a Linux environment.  That's why it works great on Ubuntu. &lt;strong&gt;How you asked?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Docker container running on Ubuntu is just like a usual process running for Kernel. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If we expose the port from the container with &lt;code&gt;-p&lt;/code&gt; option we can access it on the host.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker container run -p &amp;lt;host port&amp;gt;:&amp;lt;container port&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If we used a volume (memory space outside the container) for a container in Ubuntu we can see and access that from our host machine. Because it is on your host machine and you can access that just like another file. Seems obvious, yes it is but for Ubuntu. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Mac OS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, understand this that for Mac OS Docker has two way to go. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker Toolbox (The old way)&lt;/li&gt;
&lt;li&gt;Docker for Mac (The new way)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you stuck at a point and you went over to stack overflow there might be a chance you will see an answer which is supposed to run on Docker Toolbox and you are running that on Docker for Mac and eventually &lt;strong&gt;messed up everthing&lt;/strong&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Docker Toolbox
&lt;/h3&gt;

&lt;p&gt;Everywhere you read they say that docker does not run on a VM, it runs on the host OS. Well here comes the twist. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Docker Toolbox &lt;strong&gt;do run a VM of Linux&lt;/strong&gt; on Mac OS on which your Docker containers run.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So if you are using this toolbox remember that you have a virtual OS of Linux in between your Mac OS and docker container. &lt;strong&gt;How this affects your system, you asked?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now if you expose a port form Docker container it will be exposed to the Linux OS and not directly to Mac OS. &lt;strong&gt;Now you need to expose that port from Linux OS to Mac OS&lt;/strong&gt;. See, extra work and a headache.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If your Docker container uses a volume, it will be on &lt;strong&gt;Linux OS&lt;/strong&gt; and &lt;strong&gt;not&lt;/strong&gt; on your MacOS. Which means you &lt;strong&gt;can't&lt;/strong&gt; access it, knowing that it exists. &lt;br&gt;
If you want to see that, then you need to screen into that Linux OS and then access that volume. See another headache.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Docker for Mac
&lt;/h3&gt;

&lt;p&gt;With the new version, for mac, they have removed the heavy Linux layer from in-between which uses VM.&lt;br&gt;
Instead, now docker is a native application &lt;strong&gt;but&lt;/strong&gt; it still uses a &lt;strong&gt;native virtualization framework&lt;/strong&gt; called &lt;a href="https://github.com/moby/hyperkit"&gt;&lt;strong&gt;HyperKit&lt;/strong&gt;&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;How does it affect you?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you expose the port from the container it will be available to your host. So no more OS exposing in between. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;But we still can't access the volumes of Docker containers directly from the host. They are still inside that lightweight Linux layer. See &lt;a href="https://stackoverflow.com/a/41281658/6274382"&gt;this&lt;/a&gt; for more information on how you can access those.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;p&gt;If you run into some weird problem with docker container then do remember the followings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In Ubuntu (or other Linux) there is no middle layer between docker containers and host OS. And I guess 90% of the time your production OS is also Ubuntu. But on your MacOS there is a layer in between.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Although Docker team has worked wonderfully to make it as native as it can be but there is still a light layer of Linux in between MacOS and containers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Also check that the solution on stack-overflow might be for Docker Toolbox and not for Docker for Mac (new version).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If it can help anyone struggling to make things work with docker, it serves the purpose.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thank you so much for reading, and let's discuss more in the comment section. Throw away your thoughts on this and point out if I made mistake. Let's learn together. &lt;/p&gt;

</description>
      <category>docker</category>
      <category>knowyourtools</category>
      <category>productivity</category>
      <category>deepunderstanding</category>
    </item>
    <item>
      <title>Service object | Shots #1</title>
      <dc:creator>Raounak Sharma</dc:creator>
      <pubDate>Tue, 19 Feb 2019 16:07:43 +0000</pubDate>
      <link>https://dev.to/where_i_stuck/service-object--shots-40cb</link>
      <guid>https://dev.to/where_i_stuck/service-object--shots-40cb</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SkTA8C5v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.jurassicworld.com/sites/default/files/2018-06/960x540_0001_trex.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SkTA8C5v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://www.jurassicworld.com/sites/default/files/2018-06/960x540_0001_trex.png" alt="dinosaur"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What is it?
&lt;/h1&gt;

&lt;p&gt;Let's talk in simple words, services are just a thing which serves a  purpose. Now before saying that it is rubbish just hold on with me.&lt;/p&gt;

&lt;p&gt;Serves the purpose in making software means that it do something for a class that the class itself is not meant to do (following single responsibility principle). Now that class can be anything in any framework for example model class in Rails and component class in Angular.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why we need them?
&lt;/h1&gt;

&lt;p&gt;Actually, we only need them in case of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the same logic is used in more than one place. And our ability to modify the same thing over multiple places is not too good.&lt;/li&gt;
&lt;li&gt;If the app is ever going be changed or modified.  I think it will be.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So if our code is ever going to be modified/expanded and we do want to follow DRY and SR principles, then I guess we need to do it.&lt;/p&gt;

&lt;h1&gt;
  
  
  How we do them?
&lt;/h1&gt;

&lt;p&gt;A service is nothing, but just another class. Also doing something around a single responsibility.&lt;br&gt;
Example: A class handling calling to Twitter API.&lt;/p&gt;

&lt;p&gt;Now make an object of this class in whatever class you required and use it to do its things while the class in which you called it will only use the output of this service object.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Now, how you can actually do them in different languages/framework is your next search, I just gave you a reason to search.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>serviceobjects</category>
      <category>angular</category>
      <category>singleresponsibility</category>
      <category>cleancode</category>
    </item>
    <item>
      <title>VS-Code | Know your tools #1</title>
      <dc:creator>Raounak Sharma</dc:creator>
      <pubDate>Fri, 14 Dec 2018 12:52:03 +0000</pubDate>
      <link>https://dev.to/where_i_stuck/know-your-tools-vs-code-5ckd</link>
      <guid>https://dev.to/where_i_stuck/know-your-tools-vs-code-5ckd</guid>
      <description>&lt;p&gt;Productivity everybody wants it. Everybody thinks they are. But can we improve?&lt;/p&gt;

&lt;p&gt;I think one way is to know our tools. What they are capable of? What are the features they provide? and Are we not using them all? Are we not using them to their full power?&lt;/p&gt;

&lt;p&gt;Here I share 5 productivity features of VS-Code I use.&lt;/p&gt;

&lt;p&gt;It doesn’t matter what application you are building or what stack your are following. Every developer has his favorite text editor or at-least he prefers to use one by default. As you have guessed from the title for me it is VS-Code.&lt;/p&gt;

&lt;p&gt;What I want to share is not how to install it or why it is better than other, for that we have a ton of other resources. What I can provide is my experience with vs-code in increasing productivity.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We will try to stay away from the mouse as much as possible.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's start the journey&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftdsq8cks88lud7l1fcv0.jpg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftdsq8cks88lud7l1fcv0.jpg" alt="Starting a journey"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Integrated Terminal
&lt;/h2&gt;

&lt;p&gt;This feature has saved me a lot of time. if you are not using this then you may find yourself keep toggling between your text editor and terminal. I use my VS-Code for Angular and Rails development, and for Angular, it doesn’t matter much but for Rails when I am making model and using Rails console then it helps a lot.&lt;/p&gt;

&lt;p&gt;What is it? Nothing, the same terminal you have. It’s just now visible in your text editor as shown in figure 2. Here VS-Code.&lt;/p&gt;

&lt;p&gt;How I suggest using it is, making a keyboard shortcut to toggle focus between terminal and file. Here is my &lt;code&gt;keybinding.json&lt;/code&gt; to show you how I have made it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
// Toggle between terminal and editor focus
{ "key": "ctrl+`", "command": "workbench.action.terminal.focus"},
{ "key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I use the inbuilt terminal to usually do git commits and run app server in the separate terminals (For that I use iTerm 2).&lt;/p&gt;

&lt;p&gt;Again going specifically I use git rebase, stash, pull and push commands here. For my usual commands like commit(with small messages), add and diff VS code provide a great way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multiple session&lt;/strong&gt; is also a thing I use when I ssh into my EC2 instance. You can open another session by pressing the small + sign at the top right corner.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzv9ivr0d0n89znua47ot.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzv9ivr0d0n89znua47ot.png" alt="VS code terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why I did like this is because when I SSH into EC2 instances of my Rails and the Angular app, from my iTerm sessions then soon I forgot which terminal is which instance. So now I do it inside the vs-code terminal and it keeps it clear in my mind.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Git Support
&lt;/h2&gt;

&lt;p&gt;The best thing I like in git support of VS-Code is how it shows the output of git diff. We don’t actually write the command in terminal. They have provided a GUI for this.&lt;/p&gt;

&lt;p&gt;Click the git branch logo in the left icon panel and then click the file for which you want to see the git diff. An example of which I have shown below.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1te3e1cj7rnbpgc5psq6.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1te3e1cj7rnbpgc5psq6.png" alt="Git diff photo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I just edited one file in any Angular project. and you can see, how amazingly it show what has deleted and what has added, i.e what has changed. This is amazing and for me I think better than how git shows the output in terminal. Git engineers has made a ton of efforts in making the feature of &lt;code&gt;git diff&lt;/code&gt; ,I respect that a lot and I like it, this is just make it more easy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;git add, git commit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I also use the VS-Code GUI functionality to add files in staging and to commit them if I have a small commit message.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvlec4s4h3bgwace94c3p.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvlec4s4h3bgwace94c3p.png" alt="Git panel of VSCode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can do this by using the panel at left. The small + sign is used to add the corresponding file to staging state, the curved back arrow is used to revert the changes and the input field above the file name as you can see is used for commit message. For medium size commit message I use integrated terminal and the same old vim fashion method.&lt;/p&gt;

&lt;p&gt;Why I use this? because I can add files to staging section very fast as compared to adding them by using &lt;code&gt;git add &amp;lt;file path&amp;gt; command&lt;/code&gt;. That writing file path in angular project is very boring, because of lots of sub folder and sub sub folders, yes even by using &lt;code&gt;tab&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens" rel="noopener noreferrer"&gt;Git Lens (The best thing around git log)&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
It’s a plugin/extension available in VS-Code extensions marketplace. I just love how it shows the history of any file in terms of which user has done what in that file.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd3mz9ohpm8uqr67kff26.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd3mz9ohpm8uqr67kff26.png" alt="History of files by Gitlens"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above picture shows a file history. When it was added i.e 15 days ago, who added that, int what commit it was added/changed. The commit hash is available on left side panel under file history.&lt;/p&gt;

&lt;p&gt;It is showing the complete git log of a file, without evening writing any git command. Isn’t it awesome. Also this functionality is extended to all git branches under all remotes you have. A glimpse of which I have added in the figure 6. (Although I have only one remote)&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F5r00go3hkdmuxu4jt7qu.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F5r00go3hkdmuxu4jt7qu.png" alt="History of branch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These functionality helps moving fast with Git and keeping a track in Git logs and all those merge conflicts.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Peak Definition
&lt;/h2&gt;

&lt;p&gt;Working on any large project or a project having lots and lots of code distributed among multiple files will lead to jumping from one file to other more frequently.&lt;/p&gt;

&lt;p&gt;And in case if you just want to see some method definition in other file and then move back to your original file seems a big work to you like me, then this is a saver.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fs25w3yeocaobew4784x9.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fs25w3yeocaobew4784x9.png" alt="Peak definition"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;right click + peak definition&lt;/code&gt; or &lt;code&gt;press ⌥F12&lt;/code&gt;, is the method to open this beauty. It will show you the definition and if you want you can make changes in the peak file as well from there. In case if there are multiple definition of keyword match it will show all of them, and you can choose the right one. But ya here we break our rule of not touching the mouse.&lt;/p&gt;

&lt;p&gt;It saves me from headache I got from frequently changing files and also it looks cool. Damn cool&lt;/p&gt;

&lt;p&gt;Still I need to open files from folders buried deep inside the tree structure of folders and lots of folders. For that I use the tool below:&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;a href="https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette" rel="noopener noreferrer"&gt;Command Pallet&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This is the common feature among all new text editors. Hit &lt;code&gt;Cmd + P&lt;/code&gt; and then write the file name you want to open, a dropdown will come according to matching results and you can choose from them. Fast and easy way to access files and the good part is it also open the folder containing that file in left panel and focus the current opened file.&lt;/p&gt;

&lt;p&gt;There is a lot you can do with command pallet like running inbuilt or your custom tasks, opening a file, and any sort of command which VS-Code provide you can run from there. For how to do this and that hit this &lt;a href="https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette" rel="noopener noreferrer"&gt;link&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Debugger
&lt;/h2&gt;

&lt;p&gt;I love the &lt;a href="https://github.com/deivid-rodriguez/byebug" rel="noopener noreferrer"&gt;&lt;strong&gt;byebug&lt;/strong&gt;&lt;/a&gt; gem in ruby. Debugging in Rails is cake walk, all thanks to the hard working engineers making our life easy. But when it comes to javascript things are not that much self explanatory. If you know Rails you must have used byebug or &lt;a href="https://github.com/pry/pry" rel="noopener noreferrer"&gt;&lt;strong&gt;pry&lt;/strong&gt;&lt;/a&gt; gem for debugging.&lt;/p&gt;

&lt;p&gt;It helps a lot by stopping your server at any time and see what is the state at that point.&lt;/p&gt;

&lt;p&gt;In JavaScript I used &lt;code&gt;console.log&lt;/code&gt; everywhere when I need to debug. This was my goto in any case dealing with JS. Then came the Debugger of VS-Code. It makes the experience similar by stopping the code at any point and see what is the state of app.&lt;/p&gt;

&lt;p&gt;What I need to do is just mark a red dot against the line number where I want to stop the code and run the debugger.&lt;/p&gt;

&lt;p&gt;It requires a file name &lt;code&gt;launch.json&lt;/code&gt; to be configured so that it can know which server to target and which platform to run the app. For my Angular app I use chrome plugin of debugger and mark my default localhost:4200 as server port to run. Follow this for setup and usage of debugger.&lt;/p&gt;

&lt;p&gt;These are my 5 best features I use in VS-code to maximize my productivity and ease my process of development.&lt;/p&gt;

&lt;p&gt;Before wrapping up there is one more very interesting feature VS-Code has which is &lt;a href="https://code.visualstudio.com/blogs/2017/11/15/live-share" rel="noopener noreferrer"&gt;live-share&lt;/a&gt;. This is very amazing if you do a lot of pair programming. Live Share enables your team to quickly collaborate on the same codebase without the need to synchronize code or to configure the same development tools, settings, or environment.&lt;/p&gt;

&lt;p&gt;They have an amazing &lt;a href="https://code.visualstudio.com/blogs/2017/11/15/live-share" rel="noopener noreferrer"&gt;video&lt;/a&gt; to explain this, I havn’t used this feature but I think this is one of the best in market right now in its field.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fe067ob7doljgevgb2w1w.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fe067ob7doljgevgb2w1w.png" alt="Congrats"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you made it till the last then, congratulations now you know your tool. It’s powerful features and now you can use it to it’s full potential and increase the quality of you work.&lt;/p&gt;

&lt;p&gt;Hit the comment section below and let me know in case I missed any awesome feature and your thoughts on this.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>git</category>
      <category>betterdev</category>
      <category>debugging</category>
    </item>
  </channel>
</rss>
