<?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: Tohid Heshmati</title>
    <description>The latest articles on DEV Community by Tohid Heshmati (@tohidheshmati).</description>
    <link>https://dev.to/tohidheshmati</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%2F141051%2Fbd37096a-ef46-4b13-9802-e643af1a978c.jpg</url>
      <title>DEV Community: Tohid Heshmati</title>
      <link>https://dev.to/tohidheshmati</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tohidheshmati"/>
    <language>en</language>
    <item>
      <title>git stash for dummy’s</title>
      <dc:creator>Tohid Heshmati</dc:creator>
      <pubDate>Thu, 19 Sep 2019 12:16:21 +0000</pubDate>
      <link>https://dev.to/tohidheshmati/dirty-temporary-commit-369m</link>
      <guid>https://dev.to/tohidheshmati/dirty-temporary-commit-369m</guid>
      <description>&lt;p&gt;git stash for dummy’s or dirty &amp;amp; temporary commit&lt;/p&gt;

&lt;p&gt;I strongly believe in learning the core of something with simple steps and then broaden the knowledge by exploring options.&lt;/p&gt;

&lt;p&gt;I encountered "git stash" just yesterday and here is the simple steps towards it and.&lt;/p&gt;

&lt;p&gt;Scenario: I have worked on a task and in middle of it read on team slack that &lt;/p&gt;

&lt;p&gt;&lt;code&gt;the develop branch has been updated. please update your branches&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But I'm still in middle of my work. I have written lines of codes on my own branch. I don't want to commit or delete my code. Deleting is waste of time. If I do commit, it would be a bad commit because I'm not sure about my work. But I want my develop branch to be updated. what should I do?&lt;/p&gt;

&lt;p&gt;The way to go is STASH. by stashing we save our dirty work and easily switch to other branches, update them and get back to our work.&lt;/p&gt;

&lt;p&gt;lets call it dirty &amp;amp; temporary commit.&lt;/p&gt;

&lt;p&gt;first thing to do is to do this dirty commit. instead of normal git commit message this is the command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to have a message like commit message we can choose save option like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash save "message"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now we are free to go to other branches and do any kind of update. in my case: checking out develop branch + pulling from origin + merging it to my Task branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout develop

git pull origin develop

git checkout my_Task_Branch_Name

git merge develop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now our project is up to date. but we miss codes that we have written. to see all the stashed (or our little secrete ;) temporary committed)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash list 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you will see one or more stash. it is strongly recommended not to have more than one stash.&lt;br&gt;
anyway you need your code back, to bring back your stashed code you have to apply it using this command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash apply stash@{number}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so far you are done. congrats. you are both updated and have your code back. if the list of stashes bothers you as it bothers me try the pop option to apply and delete.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash pop stash@{number}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or to clear all of it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash clear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
git&lt;/p&gt;

&lt;p&gt;Also it's good to note that by using &lt;code&gt;drop&lt;/code&gt; option you can delete specific or all of your git stashed codes. One may say that &lt;code&gt;pop&lt;/code&gt; option is much better because it applies and drops at the same time. So &lt;code&gt;pop&lt;/code&gt; is somehow the combination of those two. It can be good but I'm personally not fan of it. It might cause you problems. At least at beginning it's good Idea to use &lt;code&gt;apply&lt;/code&gt; &amp;amp; &lt;code&gt;drop&lt;/code&gt; separately.&lt;/p&gt;

&lt;p&gt;you may also encounter ~WIP~ a lot and is good to know that it stands for ~Work In Progress~.&lt;/p&gt;

&lt;p&gt;to see more options and possibilities check &lt;a href="https://git-scm.com/docs/git-stash"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>stash</category>
      <category>commit</category>
    </item>
    <item>
      <title>toString or not to toString?  This is the question</title>
      <dc:creator>Tohid Heshmati</dc:creator>
      <pubDate>Fri, 01 Mar 2019 21:31:27 +0000</pubDate>
      <link>https://dev.to/tohidheshmati/tostring-or-not-to-tostring--this-is-the-question-5coa</link>
      <guid>https://dev.to/tohidheshmati/tostring-or-not-to-tostring--this-is-the-question-5coa</guid>
      <description>&lt;p&gt;A &lt;strong&gt;"Hello World!"&lt;/strong&gt; program which prints this sentence on the screen is the very first program almost any programmer writes.&lt;br&gt;
It might have happened to you that you passed an Object to print or println methods and as a result have received a weird &lt;strong&gt;name@number&lt;/strong&gt; answer.&lt;br&gt;
In this example we pass an Object to println function without any addition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ActionClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Odyssey"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"Homer"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;author&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Result might appear as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="err"&gt;5&lt;/span&gt;&lt;span class="nt"&gt;a39699c&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Classes are known as &lt;strong&gt;reference variable&lt;/strong&gt;. a reference variable is capable of storing the location of an object.&lt;br&gt;
By going a little more in in detail we see that the reason is because of print function's implementation. By passing an Object to a print function the actual command that we write is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;System&lt;/span&gt;&lt;span class="nc"&gt;.out.println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;book&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what Java sees and runs is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;System&lt;/span&gt;&lt;span class="nc"&gt;.out.println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;book&lt;/span&gt;&lt;span class="nc"&gt;.toString&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hmmm. Now we have another Method to look at. Under the hood toString() method looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getClass&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"@"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toHexString&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;hashCode&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aha, that explains the mysterious case of &lt;strong&gt;className@weirdNumber&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Any suggestion?&lt;br&gt;
yes of course. By overriding the &lt;strong&gt;toString()&lt;/strong&gt; method for our Object we can easily pass the object to print methods without turning them to strings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Override&lt;/span&gt;
        &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Book{"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="s"&gt;"name='"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sc"&gt;'\''&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="s"&gt;", author='"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;author&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sc"&gt;'\''&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                    &lt;span class="sc"&gt;'}'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After doing so the first code we wrote in this article will have a result as below without adding &lt;strong&gt;toString()&lt;/strong&gt; method to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;name='Odyssey',&lt;/span&gt; &lt;span class="err"&gt;author='Homer'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>java</category>
      <category>tostring</category>
      <category>beginners</category>
      <category>override</category>
    </item>
  </channel>
</rss>
