<?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: Sukma Wardana</title>
    <description>The latest articles on DEV Community by Sukma Wardana (@sukma_wardana).</description>
    <link>https://dev.to/sukma_wardana</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%2F1264795%2F90c7b1d0-9681-4980-a451-33490c520ddb.png</url>
      <title>DEV Community: Sukma Wardana</title>
      <link>https://dev.to/sukma_wardana</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sukma_wardana"/>
    <language>en</language>
    <item>
      <title>Remove Gibberish Messages in Git</title>
      <dc:creator>Sukma Wardana</dc:creator>
      <pubDate>Tue, 13 Feb 2024 12:51:36 +0000</pubDate>
      <link>https://dev.to/sukma_wardana/remove-gibberish-messages-in-git-1fnj</link>
      <guid>https://dev.to/sukma_wardana/remove-gibberish-messages-in-git-1fnj</guid>
      <description>&lt;p&gt;&lt;em&gt;I am a perfectionist&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I want to do everything perfectly, including writing commit messages in Git. Whenever I need to work on new features or fix bugs, I will create a new Git branch.&lt;/p&gt;

&lt;p&gt;But, I can't avoid writing crapy and meaningless commit messages, especially when change a piece of code many times just because need to trigger the CI/CD pipelines.&lt;/p&gt;

&lt;p&gt;Here is an example. I was working on a new feature of my project. I will create a new branch called &lt;strong&gt;feat/shinning&lt;/strong&gt;. After working on the code, here are the commit logs when I type &lt;code&gt;git log&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;commit c62397c29f5a299c814d7a138092fc345448dc05 (HEAD -&amp;gt; installer, origin/installer)
Author: swardana 
Date:   Wed Oct 11 21:22:14 2023 +0700

        change styles

commit 4cbf76038d2d6685dacf0f253341d057ce348f50
Author: swardana 
Date:   Wed Oct 11 21:11:04 2023 +0700

        fix typos

commit 8a5dcd63364263dfda0f2ec38a609c3de53c3c08
Author: swardana 
Date:   Thu Oct 5 21:04:05 2023 +0700

        fix once again

commit 3abc24267d4130a9e9b58c051f406249054a906f (origin/main, main)
Author: swardana 
Date:   Tue Oct 3 22:12:13 2023 +0700

        wrong class
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, now you know how messy and meaningless my commit messages are. I could still merge the &lt;strong&gt;feat/shinning&lt;/strong&gt; into the &lt;strong&gt;main&lt;/strong&gt;, but I hate to &lt;em&gt;see that&lt;/em&gt; on my logs history.&lt;/p&gt;

&lt;p&gt;My goal is to &lt;em&gt;combine all the commits&lt;/em&gt; into only one &lt;em&gt;meaningful&lt;/em&gt; commit message.&lt;/p&gt;

&lt;p&gt;There are multiple ways to achieve it. But, what works for me is this. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Working with temporary branch&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rather than create a proper branch, I will create a temporary branch and I could put many crapy or silly commit messages there.&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 -b tmp/shinning
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Create proper branch&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When done with the changes and ready to merge it, I will create a new branch from the commit in the &lt;strong&gt;main&lt;/strong&gt; branch where the &lt;strong&gt;temporary branch&lt;/strong&gt; is initiated.&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 main
$ git checkout -b feat/shinning ecddf76
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Merge the temporary branch to the real branch with --squash option&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git merge --squash tmp/shinning
$ git commit # without -m
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When enter the &lt;code&gt;git commit&lt;/code&gt;, &lt;em&gt;without -m&lt;/em&gt;, an editor should be popup with all the commit logs, and files changed from the &lt;strong&gt;tmp/shinning&lt;/strong&gt;. I will delete everything and write proper commit message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Merge the real branch to main&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the last and final step, merge the real branch to the &lt;strong&gt;main&lt;/strong&gt;.&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 main
$ git merge feat/shinning
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, it's done. With this, I could avoid any crapy and messy commit messages in my logs history.&lt;/p&gt;

&lt;p&gt;This is inspired from the &lt;a href="https://stackoverflow.com/a/60714645/5852226"&gt;Stack Overflow&lt;/a&gt; answer which refer to this &lt;a href="https://github.com/rotati/wiki/wiki/Git:-Combine-all-messy-commits-into-one-commit-before-merging-to-Master-branch"&gt;Github Wiki&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>Absolute Number in C Language</title>
      <dc:creator>Sukma Wardana</dc:creator>
      <pubDate>Tue, 30 Jan 2024 09:27:30 +0000</pubDate>
      <link>https://dev.to/sukma_wardana/absolute-number-in-c-language-1aak</link>
      <guid>https://dev.to/sukma_wardana/absolute-number-in-c-language-1aak</guid>
      <description>&lt;p&gt;An absolute value in mathematics is defined as the non-negative value of x without regard to its sign. The notation of absolute value is a vertical bar on each side of the variable |x|. So, by theory |-16| will become 16.&lt;/p&gt;

&lt;p&gt;Now, &lt;em&gt;how could I bring this into the C programming language&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;The easiest way is to use the &lt;a href="https://pubs.opengroup.org/onlinepubs/009695399/functions/abs.html"&gt;abs&lt;/a&gt; API from the stdlib.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, &lt;em&gt;what if there is a situation in which you can't use stdlib or any libraries&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;I experienced this before and was helpless. Thus, I decided to employ my &lt;em&gt;Google-fu&lt;/em&gt; to learn how to implement absolute value without any libraries.&lt;/p&gt;

&lt;p&gt;Then, I found the &lt;a href="https://copyprogramming.com/howto/c-how-to-make-absolute-value-in-c#get-absolute-value-without-using-abs-function-nor-if-statement"&gt;simple and easy-to-implement solutions&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="nf"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The source explained it better and was easy to understand. But what made me surprise is, how it leverages the characteristics of C programming language. Which is, in C we don't have a boolean data type.&lt;/p&gt;

&lt;p&gt;In C language, to determine true or false it's using an integer value. Zero represents false and One represents true. So, let's examine how the parentheses value outcome will be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;(x&amp;gt;0):&lt;/strong&gt; True (1) if x greater than 0, False (0) otherwise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;(x&amp;lt;0):&lt;/strong&gt; True (1) if x less than 0, False (0) otherwise.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's break down when the x is a positive number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x == 10
result = x  * ((x&amp;gt;0) - (x&amp;lt;0))
result = 10 * (  1   -   0  )
result = 10 * 1
result = 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break down when the x is a negative number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x == -16
result =  x  * ((x&amp;gt;0) - (x&amp;lt;0))
result = -16 * (  0   -   1  )
result = -16 * -1
result =  16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And lastly, if the x is a zero.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x == 0
result =  x * ((x&amp;gt;0) - (x&amp;lt;0))
result =  0 * (  0   -   0  )
result =  0 * 0
result =  0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;absolute&lt;/code&gt; method will never alter the &lt;code&gt;x&lt;/code&gt; when it's a positive or zero number. But, when we set the &lt;code&gt;x&lt;/code&gt; as a negative number we negate it by multiplying with -1 to get a positive number from &lt;code&gt;x&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What an interesting solution.&lt;/p&gt;

</description>
      <category>c</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Introduction</title>
      <dc:creator>Sukma Wardana</dc:creator>
      <pubDate>Wed, 24 Jan 2024 13:10:05 +0000</pubDate>
      <link>https://dev.to/sukma_wardana/introduction-4406</link>
      <guid>https://dev.to/sukma_wardana/introduction-4406</guid>
      <description>&lt;p&gt;Hey!&lt;/p&gt;

&lt;p&gt;This is the first. Therefore, it's not about anything in particular–just an introduction and my way to greet my future cyber friends.&lt;/p&gt;

&lt;p&gt;This will be primarily about software development ideas. I'm passionate about open source software and pragmatic thinking. I will write solely about my ideas and views on it.&lt;/p&gt;

&lt;p&gt;Anyway, welcome. Together, let's see how this works out! :)&lt;/p&gt;

</description>
      <category>introduction</category>
      <category>newtodev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
