<?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: Rusydy</title>
    <description>The latest articles on DEV Community by Rusydy (@rusydy).</description>
    <link>https://dev.to/rusydy</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%2F312778%2F44433eae-734a-4277-a5d9-fec99a0625f6.png</url>
      <title>DEV Community: Rusydy</title>
      <link>https://dev.to/rusydy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rusydy"/>
    <language>en</language>
    <item>
      <title>Conquering System Design Diagrams: My Shift to Mermaid.js</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Sat, 30 Mar 2024 04:58:35 +0000</pubDate>
      <link>https://dev.to/rusydy/conquering-system-design-diagrams-my-shift-to-mermaidjs-5bol</link>
      <guid>https://dev.to/rusydy/conquering-system-design-diagrams-my-shift-to-mermaidjs-5bol</guid>
      <description>&lt;p&gt;Diagrams are the cornerstone of software development, illuminating complex systems and fostering clear communication. However, traditional diagramming tools often lack crucial features, hindering efficient system design documentation.&lt;/p&gt;

&lt;p&gt;My workflow previously relied on draw.io, a great tool for creating simple diagrams with its intuitive interface and extensive shape library. However, managing intricate system designs became cumbersome. Frequent revisions meant manually updating the entire diagram, leading to version control issues and lost design context.&lt;/p&gt;

&lt;p&gt;Here's how &lt;code&gt;Mermaid.js&lt;/code&gt; revolutionized my diagramming journey:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Embracing Version Control with &lt;code&gt;Mermaid.js&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Mermaid.js&lt;/code&gt;, a text-based diagramming tool, revolutionized my approach. Its seamless integration with Git ensures meticulous version control. Every change is meticulously tracked, allowing me to revisit previous design iterations effortlessly. This eliminates confusion and streamlines design decision recall.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. More Control and Collaboration:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Unlike cloud-based tools, &lt;code&gt;Mermaid.js&lt;/code&gt; empowers local file management. Diagrams reside directly on my machine, integrating flawlessly with Git for version control. Additionally, embedding diagrams within Markdown files fosters collaborative workflows. Teams can access the latest version and contribute edits directly on GitHub, boosting efficiency by working on a single source of truth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Simplicity Breeds Power:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Mermaid.js&lt;/code&gt; utilizes a clear and concise text-based syntax, making it remarkably user-friendly. While seemingly simple, it offers a robust set of features, generating a wide array of diagrams, from flowcharts and sequence diagrams to class diagrams and even pie charts. This flexibility caters to various diagramming needs within system design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Enhancing Workflow with VS Code (Optional):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The VS Code extension for &lt;code&gt;Mermaid.js&lt;/code&gt; further streamlines the process. Once installed, creating diagrams becomes effortless within Markdown files. Code blocks designated with the "mermaid" language allow you to write your diagram code. The extension offers optional features like real-time preview, enabling you to visualize changes as you write. Additionally, editing the code within VS Code automatically updates the preview, facilitating efficient iteration.&lt;/p&gt;

&lt;p&gt;In conclusion, &lt;code&gt;Mermaid.js&lt;/code&gt; has transformed my diagramming workflow, offering a seamless and collaborative approach to system design documentation. By leveraging local control, version control, and real-time collaboration, I've transitioned from diagramming frustration to clarity and efficiency.&lt;/p&gt;

&lt;p&gt;Here are some resources to get you started:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Official Website:&lt;/strong&gt; &lt;a href="https://%20raw%20`Mermaid.js`%20endraw%20.org/" rel="noopener noreferrer"&gt;https://mermaid.js.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interactive Tutorial:&lt;/strong&gt; &lt;a href="https://github.com/mermaid-js/mermaid-live-editor" rel="noopener noreferrer"&gt;https://github.com/mermaid-js/mermaid-live-editor&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VS Code Extension:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid" rel="noopener noreferrer"&gt;Markdown Preview Mermaid Support&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=Bpruitt-Goddard.mermaid-markdown-syntax-highlighting" rel="noopener noreferrer"&gt;Mermaid Markdown Syntax Highlighting&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Example Repository:&lt;/strong&gt; &lt;a href="https://github.com/Rusydy/diagram_as_code_example" rel="noopener noreferrer"&gt;Diagram as Code&lt;/a&gt;
&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Using LUTs (Look-Up Tables) Data Structures to simplify code’s logic and more</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Sat, 30 Dec 2023 07:06:38 +0000</pubDate>
      <link>https://dev.to/rusydy/using-luts-look-up-tables-data-structures-to-simplify-codes-logic-and-more-3ghi</link>
      <guid>https://dev.to/rusydy/using-luts-look-up-tables-data-structures-to-simplify-codes-logic-and-more-3ghi</guid>
      <description>&lt;h2&gt;
  
  
  Issues
&lt;/h2&gt;

&lt;p&gt;When I was working on a feature to check the transaction’s status from a third-party service, I had to deal with plenty of possible combinations of values that could be returned by the service. The code was getting more and more complex, with each response status have its own description and action to be taken. Here is a simplified version of the code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;thirdParty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;CheckTransactionStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c"&gt;/* request */&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="n"&gt;CheckTransactionStatusRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c"&gt;/* response */&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="n"&gt;CheckTransactionStatusResponse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpStatusCode&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CheckTransactionStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&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;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusInternalServerError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"SUCCESS"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusOK&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"PENDING"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusAccepted&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"FAILED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusBadGateway&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"REJECTED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusForbidden&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"CANCELLED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"EXPIRED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"REFUNDED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"CHARGEBACK"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"ERROR"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusBadGateway&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
        &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusInternalServerError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;New&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"unknown status"&lt;/span&gt;&lt;span class="p"&gt;)&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 code above was performing many conditional checks to return the correct HTTP status code. It also had a lot of duplicated code. That makes me ask myself;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;what if I need to add a new status code?&lt;/li&gt;
&lt;li&gt;what if I need to add a new description? Or action to be taken?&lt;/li&gt;
&lt;li&gt;can I add in-depth logging to the code? And update it easily in the future?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;I decided to use a LUT (Look-Up Table) data structure to simplify the code’s logic. The LUT is a data structure that associates keys with values. It is a simple way to replace a lot of if/else statements or switch/case statements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 1: Using a LUT to replace if/else statements
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;transactionStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;"SUCCESS"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusOK&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"PENDING"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusAccepted&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"FAILED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusBadGateway&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"REJECTED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusForbidden&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"CANCELLED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"EXPIRED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"REFUNDED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"CHARGEBACK"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"ERROR"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusBadGateway&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;thirdParty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;CheckTransactionStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c"&gt;/* request */&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="n"&gt;CheckTransactionStatusRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c"&gt;/* response */&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="n"&gt;CheckTransactionStatusResponse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpStatusCode&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CheckTransactionStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&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;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusInternalServerError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;transactionStatus&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;found&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;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusInternalServerError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;New&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"unknown status"&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;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;The code above is a lot simpler than the previous one. It is also easier to add a new status code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 2: Using a LUT to add in-depth logging
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;transactionStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="n"&gt;httpStatusCode&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;br&gt;
    &lt;span class="n"&gt;logLevel&lt;/span&gt;       &lt;span class="kt"&gt;string&lt;/span&gt;&lt;br&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;    &lt;span class="kt"&gt;string&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;}{&lt;/span&gt;&lt;br&gt;
    &lt;span class="s"&gt;"SUCCESS"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusOK&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;logLevel&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="s"&gt;"info"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;"transaction was successful"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
    &lt;span class="s"&gt;"PENDING"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusAccepted&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;logLevel&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="s"&gt;"info"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;"transaction is pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
    &lt;span class="s"&gt;"FAILED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusBadGateway&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;logLevel&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="s"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;"transaction failed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
    &lt;span class="s"&gt;"REJECTED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusForbidden&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;logLevel&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="s"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;"transaction was rejected"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
    &lt;span class="s"&gt;"CANCELLED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;logLevel&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="s"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;"transaction was cancelled"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
    &lt;span class="s"&gt;"EXPIRED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;logLevel&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="s"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;"transaction was expired"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
    &lt;span class="s"&gt;"REFUNDED"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;logLevel&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="s"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;"transaction was refunded"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
    &lt;span class="s"&gt;"CHARGEBACK"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusGone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;logLevel&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="s"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;"transaction was charged back"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
    &lt;span class="s"&gt;"ERROR"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;httpStatusCode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusBadGateway&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;logLevel&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;       &lt;span class="s"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;"transaction had an error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;thirdParty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;CheckTransactionStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;br&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="n"&gt;CheckTransactionStatusRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;br&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="n"&gt;CheckTransactionStatusResponse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpStatusCode&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CheckTransactionStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;br&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusInternalServerError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span class="n"&amp;gt;status&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt; &amp;lt;span class="n"&amp;gt;found&amp;lt;/span&amp;gt; &amp;lt;span class="o"&amp;gt;:=&amp;lt;/span&amp;gt; &amp;lt;span class="n"&amp;gt;transactionStatus&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;[&amp;lt;/span&amp;gt;&amp;lt;span class="n"&amp;gt;resp&amp;lt;/span&amp;gt;&amp;lt;span class="o"&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class="n"&amp;gt;Status&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;]&amp;lt;/span&amp;gt;
&amp;lt;span class="k"&amp;gt;if&amp;lt;/span&amp;gt; &amp;lt;span class="o"&amp;gt;!&amp;lt;/span&amp;gt;&amp;lt;span class="n"&amp;gt;found&amp;lt;/span&amp;gt; &amp;lt;span class="p"&amp;gt;{&amp;lt;/span&amp;gt;
    &amp;lt;span class="k"&amp;gt;return&amp;lt;/span&amp;gt; &amp;lt;span class="n"&amp;gt;response&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt; &amp;lt;span class="n"&amp;gt;http&amp;lt;/span&amp;gt;&amp;lt;span class="o"&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class="n"&amp;gt;StatusInternalServerError&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt; &amp;lt;span class="n"&amp;gt;errors&amp;lt;/span&amp;gt;&amp;lt;span class="o"&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class="n"&amp;gt;New&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class="s"&amp;gt;"unknown status"&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;)&amp;lt;/span&amp;gt;
&amp;lt;span class="p"&amp;gt;}&amp;lt;/span&amp;gt;

&amp;lt;span class="k"&amp;gt;return&amp;lt;/span&amp;gt; &amp;lt;span class="n"&amp;gt;response&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt; &amp;lt;span class="n"&amp;gt;status&amp;lt;/span&amp;gt;&amp;lt;span class="o"&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class="n"&amp;gt;httpStatusCode&amp;lt;/span&amp;gt;&amp;lt;span class="p"&amp;gt;,&amp;lt;/span&amp;gt; &amp;lt;span class="no"&amp;gt;nil&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

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

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Pros and Cons&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Like any other data structure, LUTs have their pros and cons.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pros
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Fast Retrieval:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Look-up tables provide constant-time average complexity for retrieving values based on a key. This makes them very efficient for large datasets.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Memory Efficiency:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Look-up tables can be memory-efficient, especially when dealing with sparse data. They only store values for existing keys, reducing memory overhead.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Simplifies Code:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using a look-up table can make code more readable and maintainable. It centralizes related information and makes it easy to update or extend.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Pre-computation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Look-up tables allow for pre-computation and storage of results, reducing the need for recalculations. This is beneficial in scenarios where certain values are repeatedly used.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flexible Key-Value Mapping:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The key-value nature of a look-up table allows for flexible mappings, supporting a wide range of use cases from configuration settings to status code mappings.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Memory Overhead:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In scenarios where the key space is large or continuous, a look-up table might consume more memory than alternative data structures with more memory-efficient representations.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Limited Sorting:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Look-up tables are inherently unordered, and sorting based on keys may require additional data structures or steps.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Limited Range Queries:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you need to perform range queries on keys, look-up tables might not be the most suitable data structure, and alternatives like trees might be more appropriate.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Look-up tables are a simple and powerful data structure that can be used to simplify code logic. They are fast, memory-efficient, and flexible. They can be used in a wide range of use cases, from configuration settings to status code mappings. However, they are not suitable for all scenarios, and you should consider the pros and cons before using them.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>go</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Enhancing Code Quality and Maintainability</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Thu, 02 Nov 2023 08:21:53 +0000</pubDate>
      <link>https://dev.to/rusydy/enhancing-code-quality-and-maintainability-kfc</link>
      <guid>https://dev.to/rusydy/enhancing-code-quality-and-maintainability-kfc</guid>
      <description>&lt;p&gt;Software development is an evolving field, and it's crucial to continually improve our coding practices to maintain high code quality and ensure maintainability. In this article, we'll discuss a set of practices for writing cleaner and more maintainable code. I'll use Go as the programming language for the examples, but these practices can be applied to any language.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Enhance Code Organization by Separation of Concerns.
&lt;/h2&gt;

&lt;p&gt;When writing Go code, it's essential to create a clear separation of concerns without making the code overly complex. To achieve this, follow these steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Splitting Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start by breaking down a large function into smaller, more manageable steps. For example, consider a function that processes a user's transaction. Split it into separate functions for validation, processing, and error handling.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;processTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt; &lt;span class="n"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;validateTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&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;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;processTransactionInternal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&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;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Separate Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rewrite these individual steps as their functions in separate files. For instance, move the &lt;code&gt;validateTransaction&lt;/code&gt; and &lt;code&gt;processTransactionInternal&lt;/code&gt; functions into their respective files.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

├── main.go
├── transaction
│   ├── process.go &lt;span class="c"&gt;# processTransaction&lt;/span&gt;
│   ├── validate.go &lt;span class="c"&gt;# validateTransaction&lt;/span&gt;
│   └── internal.go &lt;span class="c"&gt;# processTransactionInternal&lt;/span&gt;
└── user
    └── process.go


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Validation as First Concern&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Always prioritize validation as the initial step in each function. Group validations based on their specific purpose, such as request validation, user validation, and VCN validation. Each validation should have its own dedicated function with well-defined request and response structures.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;validateTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;transaction&lt;/span&gt; &lt;span class="n"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Validation logic here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;validateUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// User validation logic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;validateVCN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vcn&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// VCN validation logic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Proper Error Handling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ensure that all potential errors are handled effectively. This means checking for errors and returning them, rather than ignoring or suppressing them.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

 &lt;span class="n"&gt;vcn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;validateVCNsPrecondition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;neoPG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payloadValidateVCNsPrecondition&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&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;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  2. Optimize Conditional Statements by Variable Declarations.
&lt;/h2&gt;

&lt;p&gt;When you encounter lengthy expressions inside if statements, consider declaring those expressions as variables and then using the variables within the if statements. This makes the code more readable, self-documented and easier to maintain.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;isEligibleToVote&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Lengthy expression&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;18&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="m"&gt;120&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Rewrite it with variable declarations for improved readability:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;isEligibleToVote&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;isAgeValid&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;18&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="m"&gt;120&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;isAgeValid&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  3. Minimize Reliance on Comments.
&lt;/h2&gt;

&lt;p&gt;Meaningful function and variable naming can significantly reduce the need for excessive comments. While comments are helpful, they can sometimes become outdated or misleading. Therefore, it's best to rely on self-explanatory naming conventions. For example:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="c"&gt;// Avoid&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;calculateTax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;income&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Calculate the tax of income&lt;/span&gt;
    &lt;span class="c"&gt;// ...&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// Prefer&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;calculateIncomeTax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;income&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// ...&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  4. Effective Error Logging.
&lt;/h2&gt;

&lt;p&gt;When dealing with error logging, it's crucial to classify errors correctly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For 5XX errors, include an identifier such as the user ID or card number in the interface to simplify future investigation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For non-5XX errors that may be valuable for analytical purposes, log them for analysis.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For other predefined errors, consider error logging as optional, as these cases are typically predetermined.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;processTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt; &lt;span class="n"&gt;Transaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;validateTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
        &lt;span class="n"&gt;Interface&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
        &lt;span class="n"&gt;Interface&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"response"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
        &lt;span class="n"&gt;Msg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LABEL&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" - validateTransaction"&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;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;processTransactionInternal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
        &lt;span class="n"&gt;Interface&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
        &lt;span class="n"&gt;Interface&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"response"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
        &lt;span class="n"&gt;Msg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LABEL&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" - processTransactionInternal"&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;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;




&lt;p&gt;Incorporating these practices into your code can significantly enhance its quality and maintainability. Remember that clean, well-organized code is not only easier to work with, but also benefits the entire development team by reducing bugs and making the codebase more understandable and efficient.&lt;/p&gt;

</description>
      <category>cleancode</category>
      <category>programming</category>
      <category>productivity</category>
      <category>go</category>
    </item>
    <item>
      <title>The Ease of Force-Pushing and GitHub's Safety Net</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Mon, 11 Sep 2023 01:46:47 +0000</pubDate>
      <link>https://dev.to/rusydy/the-ease-of-force-pushing-and-githubs-safety-net-3hn</link>
      <guid>https://dev.to/rusydy/the-ease-of-force-pushing-and-githubs-safety-net-3hn</guid>
      <description>&lt;p&gt;Last night, I made an intriguing discovery about the intricacies of &lt;code&gt;git commit&lt;/code&gt; amending that, I believe, is worth sharing.&lt;/p&gt;

&lt;p&gt;It turns out that once you've amended a &lt;code&gt;git commit&lt;/code&gt;, the conventional &lt;code&gt;git pull&lt;/code&gt; and &lt;code&gt;git push&lt;/code&gt; commands won't work as expected. This quirk arises due to the inherent discrepancy between the local and the remote repositories once a commit has been amended. In most cases, the local repository is regarded as the source of truth, requiring the remote repository to align with it.&lt;/p&gt;

&lt;p&gt;To illustrate this concept, consider a recent real-world scenario: I decided to remove three commits from my pull request. As anticipated, a divergence emerged between my local and remote repositories. Typically, I would have instinctively used &lt;code&gt;git push -f&lt;/code&gt; to forcefully push these changes to the remote. However, I received advice against following my muscle memory and instead opted for the traditional approach of executing &lt;code&gt;git pull&lt;/code&gt;, followed by &lt;code&gt;git push&lt;/code&gt;. To my astonishment, the remote repository still retained the three commits I had removed.&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%2Fkq2g1inkpccfa3jyfy85.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%2Fkq2g1inkpccfa3jyfy85.png" alt="The example of force records" width="800" height="556"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, I couldn't help but reflect on why my previous teams resorted to using force-pushes so frequently. However, it's important to note that there's no need for concern regarding the potential loss of tracking before and after a force-push. GitHub has an effective record-keeping system that ensures your repository's history remains intact.&lt;/p&gt;

</description>
      <category>git</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Why Developers Should Learn Vim: Crucial Use Cases and Real-World Scenarios</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Sun, 10 Sep 2023 07:14:33 +0000</pubDate>
      <link>https://dev.to/rusydy/why-developers-should-learn-vim-crucial-use-cases-and-real-world-scenarios-4d6n</link>
      <guid>https://dev.to/rusydy/why-developers-should-learn-vim-crucial-use-cases-and-real-world-scenarios-4d6n</guid>
      <description>&lt;p&gt;Developers often face the dilemma of choosing the right text editor or Integrated Development Environment (IDE) for their coding tasks. Among the many options available, Vim stands out as a versatile and efficient text editor that offers several advantages for developers. &lt;/p&gt;

&lt;p&gt;In this article, we'll explore why developers should consider learning Vim, delve into cases where Vim is crucial, and provide a real-world scenario highlighting its importance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Learn Vim?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Efficiency
&lt;/h3&gt;

&lt;p&gt;One of the primary reasons developers should consider learning Vim is its exceptional efficiency in text editing tasks. Vim's modal editing system, extensive keyboard shortcuts, and powerful text manipulation commands allow users to perform complex editing operations with speed and precision. Once you become proficient with Vim, you'll find yourself completing tasks faster than you would with traditional text editors.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Portability
&lt;/h3&gt;

&lt;p&gt;Vim is available on most Unix-based systems, including Linux and macOS. This portability ensures that your Vim skills remain relevant and usable across various platforms. Whether you're working on your local development machine or a remote server, you can count on Vim to be available.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Lightweight
&lt;/h3&gt;

&lt;p&gt;Vim is renowned for its lightweight nature. It starts quickly and uses minimal system resources, making it an excellent choice for developers who want to conserve system resources or work on older hardware without sacrificing performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Customizability
&lt;/h3&gt;

&lt;p&gt;Vim is highly customizable, allowing you to tailor it to your specific workflow and preferences. You can configure keybindings, install plugins, and create custom macros, making Vim adaptable to a wide range of development tasks and programming languages.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Command-Line Integration
&lt;/h3&gt;

&lt;p&gt;Vim seamlessly integrates with the command line, enabling developers to edit files directly from the terminal. This feature is particularly useful for making quick code changes or editing configuration files without leaving the command line environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Remote Editing
&lt;/h3&gt;

&lt;p&gt;Vim's lightweight nature and command-line integration make it an invaluable tool for remote editing tasks, especially via SSH (Secure Shell). You can edit files on remote servers efficiently, ensuring that you can manage configurations or code remotely with ease.&lt;/p&gt;

&lt;h2&gt;
  
  
  Crucial Use Cases for Vim
&lt;/h2&gt;

&lt;p&gt;Now, let's explore some crucial use cases where Vim shines:&lt;/p&gt;

&lt;h3&gt;
  
  
  Scenario: Remote Server Configuration Edits
&lt;/h3&gt;

&lt;p&gt;Imagine you are a system administrator responsible for maintaining a web server hosted on a remote Linux machine. You receive an urgent request to update the server's configuration file to resolve a critical issue. Here's why Vim becomes crucial in this scenario:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Speed&lt;/strong&gt;: Vim launches quickly and operates efficiently, even on remote servers with limited resources. This is crucial when you need to make swift changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Minimal Overhead&lt;/strong&gt;: Vim's lightweight nature ensures it won't burden the server's resources, allowing you to focus on the task at hand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Remote Editing&lt;/strong&gt;: Vim's seamless integration with the command line lets you edit files directly on the remote server. You can SSH into the server, open the configuration file with Vim, make the necessary changes, and save the file—all without the need for a graphical user interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reliability&lt;/strong&gt;: Vim is a robust and dependable text editor. You can trust it to work consistently, which is essential when dealing with critical configuration files.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By leveraging Vim in this scenario, you can efficiently and reliably update server configurations, contributing to the smooth operation of your web server and minimizing downtime.&lt;/p&gt;

&lt;p&gt;Learning Vim is a valuable investment for developers due to its efficiency, portability, lightweight nature, customizability, command-line integration, and suitability for remote editing. In real-world scenarios, such as making critical edits to remote server configuration files, Vim's capabilities shine, making it a crucial tool for developers across various domains.&lt;/p&gt;

</description>
      <category>vim</category>
      <category>programming</category>
    </item>
    <item>
      <title>Setting Up a .NET Project on macOS</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Sun, 10 Sep 2023 02:53:12 +0000</pubDate>
      <link>https://dev.to/rusydy/setting-up-a-net-project-on-macos-590m</link>
      <guid>https://dev.to/rusydy/setting-up-a-net-project-on-macos-590m</guid>
      <description>&lt;p&gt;If you're a macOS user looking to set up a .NET project, follow these steps to get started with creating a web API project using .NET Core. This guide will walk you through the process, from ensuring you have .NET Core installed to creating a model and generating a controller with CRUD (Create, Read, Update, Delete) actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Verify .NET Core Installation
&lt;/h2&gt;

&lt;p&gt;Before you begin, make sure you have .NET Core installed on your macOS. Open your terminal and run the following command to check if it's already installed:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

dotnet &lt;span class="nt"&gt;--version&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;If you don't have .NET Core installed, you can follow the steps in this guide to install it on your macOS &lt;a href="https://dev.to/rusydy/setting-up-net-on-macos-a-step-by-step-guide-14db"&gt;Setup .Net on Mac&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create a New Web API Project
&lt;/h2&gt;

&lt;p&gt;Let's start by creating a new web API project. Open your terminal and run the following command to create a new project named "RestApi":&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

dotnet new webapi &lt;span class="nt"&gt;-n&lt;/span&gt; RestApi


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

&lt;/div&gt;

&lt;p&gt;This command sets up a basic web API project structure for you to build upon.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Install Required Dependencies
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Code Generation
&lt;/h3&gt;

&lt;p&gt;For code generation, we need to install the &lt;code&gt;dotnet-aspnet-codegenerator&lt;/code&gt; tool. Run the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

dotnet tool &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; dotnet-aspnet-codegenerator


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

&lt;/div&gt;

&lt;p&gt;Next, add the Microsoft Visual Studio Web Code Generation Design package:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Entity Framework
&lt;/h3&gt;

&lt;p&gt;If you plan to use Entity Framework, you'll need to add the required packages. Run the following commands to add Entity Framework and the SQL Server provider:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet add package Microsoft.EntityFrameworkCore.SqlServer


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

&lt;/div&gt;

&lt;p&gt;These packages are essential for database operations in your .NET project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Create a Model
&lt;/h2&gt;

&lt;p&gt;In your project's &lt;code&gt;Models&lt;/code&gt; folder, create a new class named &lt;code&gt;Recipe.cs&lt;/code&gt;. You can use the following code as a starting point:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;

&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;RestApi.Models&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Recipe&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="c1"&gt;// Add other properties as needed&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;This class represents a basic model for your application. You can add additional properties as required for your specific project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Generate a Controller
&lt;/h2&gt;

&lt;p&gt;Now, you can generate a controller with CRUD actions and views using the code generator. Run the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

dotnet aspnet-codegenerator controller &lt;span class="nt"&gt;-name&lt;/span&gt; RecipesController &lt;span class="nt"&gt;-async&lt;/span&gt; &lt;span class="nt"&gt;-api&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; Recipe &lt;span class="nt"&gt;-dc&lt;/span&gt; ApplicationDbContext


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

&lt;/div&gt;

&lt;p&gt;This command generates a controller named &lt;code&gt;RecipesController&lt;/code&gt; with all the necessary CRUD actions and views. You can customize this controller to suit your project's requirements.&lt;/p&gt;

&lt;p&gt;That's it! You've successfully set up a .NET web API project on your macOS machine, created a model, and generated a controller to handle your application's functionality. You can now start building your application by adding business logic and further customizing your project as needed.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>dotnet</category>
      <category>dotnetframework</category>
      <category>dotnetcore</category>
    </item>
    <item>
      <title>Setting Up .NET on macOS: A Step-by-Step Guide</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Sat, 09 Sep 2023 07:41:28 +0000</pubDate>
      <link>https://dev.to/rusydy/setting-up-net-on-macos-a-step-by-step-guide-14db</link>
      <guid>https://dev.to/rusydy/setting-up-net-on-macos-a-step-by-step-guide-14db</guid>
      <description>&lt;p&gt;Microsoft's .NET platform is a versatile and powerful framework for developing a wide range of applications, from web and mobile to desktop and cloud-based solutions. If you're a macOS user and want to start working with .NET, you're in the right place. In this guide, we'll walk you through the steps to set up .NET on your macOS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before you begin, ensure that your macOS version meets the system requirements for .NET. You'll also need an internet connection to download the necessary components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Install Homebrew
&lt;/h2&gt;

&lt;p&gt;Homebrew is a popular package manager for macOS that simplifies the installation of various software packages, including .NET. If you don't have Homebrew installed, follow these steps to get it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Terminal, which you can find in the “Utilities” folder within the “Applications” directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install Homebrew by running the following command:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   /bin/bash &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/Homebrew/install/master/install.sh&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Follow the on-screen instructions to complete the Homebrew installation.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 2: Install .NET SDK
&lt;/h2&gt;

&lt;p&gt;The .NET Software Development Kit (SDK) contains everything you need to build and run .NET applications. With Homebrew installed, you can easily install the .NET SDK:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;In Terminal, run the following command to install the .NET SDK:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--cask&lt;/span&gt; dotnet-sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Homebrew will download and install the .NET SDK for you. This might take a few minutes, depending on your internet speed.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 3: Verify Installation
&lt;/h2&gt;

&lt;p&gt;After the installation is complete, you can verify that .NET is installed correctly by running the following command in Terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command should display the version of the .NET SDK that was installed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Optional – Install Visual Studio Code
&lt;/h2&gt;

&lt;p&gt;While you can use any text editor or integrated development environment (IDE) for .NET development, Visual Studio Code (VS Code) is a popular choice due to its excellent support for .NET development. You can install it from the macOS App Store or by downloading it from the official website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Create a New .NET Project
&lt;/h2&gt;

&lt;p&gt;Now that you have .NET installed on your macOS, you can create and run your first .NET application. Follow these steps to create a simple “Hello World” application:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Terminal and navigate to the directory where you want to create your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a new directory for your project and navigate into it. For example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;MyDotNetApp
&lt;span class="nb"&gt;cd &lt;/span&gt;MyDotNetApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the following commands to create a new console application, build it, and run it:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new console
dotnet run
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You should see “Hello World!” printed on the terminal, indicating that your .NET application is working correctly.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Congratulations! You've successfully set up .NET on your macOS machine and created your first .NET application.&lt;/p&gt;

&lt;p&gt;Now you're ready to explore the world of .NET development on macOS. You can use Visual Studio Code or your preferred code editor to build various types of applications, including web applications using ASP.NET, cross-platform desktop applications using .NET MAUI or Xamarin, and more. The .NET ecosystem offers a wide range of tools and libraries to help you develop powerful and feature-rich applications. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>dotnet</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>CLEAN GIT: Pushing Local Changes to Remote Repository Using Git</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Fri, 08 Sep 2023 19:02:09 +0000</pubDate>
      <link>https://dev.to/rusydy/sop-pushing-local-changes-to-remote-repository-using-git-58eh</link>
      <guid>https://dev.to/rusydy/sop-pushing-local-changes-to-remote-repository-using-git-58eh</guid>
      <description>&lt;p&gt;In this Standard Operating Procedure (SOP), we will walk through the process of applying CLEAN GIT principles to efficiently push our local code changes to a remote repository. This SOP assumes a Git flow with branches such as &lt;code&gt;staging&lt;/code&gt;, &lt;code&gt;local/feature&lt;/code&gt;, &lt;code&gt;UAT&lt;/code&gt;, and &lt;code&gt;main&lt;/code&gt;. It also covers scenarios where code changes may require adjustments during the review process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Git Flow Overview
&lt;/h2&gt;

&lt;p&gt;Our Git workflow involves the following branches:&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%2Fezot5lxctq2wtjf27yjx.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%2Fezot5lxctq2wtjf27yjx.png" alt="Git Flow" width="800" height="852"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;local/feature&lt;/code&gt;: This branch is dedicated to feature development.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;main&lt;/code&gt;: The main branch serves as the central location for all integrated features.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;staging&lt;/code&gt;: QA tests features from the &lt;code&gt;main&lt;/code&gt; branch.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;UAT&lt;/code&gt;: This branch is available for client testing.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PROD&lt;/code&gt;: The production-ready branch.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It's important to note that while the &lt;code&gt;main&lt;/code&gt; branch may contain untested features, the &lt;code&gt;staging&lt;/code&gt; branch is reserved for QA-tested features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pushing Local Changes to Remote Repository
&lt;/h2&gt;

&lt;p&gt;Let's delve into the steps of applying CLEAN GIT principles when pushing local code changes to the remote repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a New Branch
&lt;/h3&gt;

&lt;p&gt;Start by creating a new branch for your feature. In this example, we'll name it &lt;code&gt;feature/TICKET-1234&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

git checkout main
git pull
git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; feature/TICKET-1234


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 2: Develop the Feature
&lt;/h3&gt;

&lt;p&gt;Develop your feature by adding or modifying files. In this instance, we create a new file called &lt;code&gt;feature.txt&lt;/code&gt; and add content to it.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"This is a feature"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; feature.txt


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 3: Commit the Changes
&lt;/h3&gt;

&lt;p&gt;Commit your changes to the local repository.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

git add feature.txt
git commit


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

&lt;/div&gt;

&lt;p&gt;This will open your default text editor. You can use &lt;code&gt;vim&lt;/code&gt; or another text editor to compose your commit message. For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="o"&gt;[&lt;/span&gt;TICKET-1234]: Add feature.txt

Previously, we did not have a feature.txt file &lt;span class="k"&gt;in &lt;/span&gt;the repository.

In this commit, we add the feature.txt file to the repository.

Thus, we can now use the feature.txt file.


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 4: Fetch and Rebase the Latest Changes
&lt;/h3&gt;

&lt;p&gt;Retrieve the latest changes from the remote repository and rebase your changes onto them.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

git fetch &lt;span class="nt"&gt;--all&lt;/span&gt; &lt;span class="nt"&gt;--tags&lt;/span&gt;
git rebase &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;--autosquash&lt;/span&gt; origin/main


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

&lt;/div&gt;

&lt;p&gt;This will open your default text editor. For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

pick 1a2b3c4 &lt;span class="o"&gt;[&lt;/span&gt;TICKET-1234]: Add feature.txt


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 5: Push the Changes to the Remote Repository
&lt;/h3&gt;

&lt;p&gt;Push your changes to the remote repository.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin feature/TICKET-1234


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step 6: Create a Pull Request
&lt;/h3&gt;

&lt;p&gt;Now, create a pull request to merge your changes into the &lt;code&gt;main&lt;/code&gt; branch.&lt;/p&gt;
&lt;h2&gt;
  
  
  Handling Reviewer-Requested Changes
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Major Changes with the Same Technical Decision
&lt;/h3&gt;

&lt;p&gt;If the reviewer requests significant changes but the technical approach remains the same, you can amend your commit after making the necessary adjustments.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

git add feature.txt
git commit &lt;span class="nt"&gt;--amend&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Update the commit message to reflect the changes:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="o"&gt;[&lt;/span&gt;TICKET-1234]: Add feature.txt&lt;/p&gt;

&lt;p&gt;Previously, we did not have a feature.txt file &lt;span class="k"&gt;in &lt;/span&gt;the repository.&lt;/p&gt;

&lt;p&gt;In this commit, we add the feature.txt file to the repository.&lt;/p&gt;

&lt;p&gt;Thus, we can now use the feature.txt file.&lt;/p&gt;

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

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Major Changes with a Different Technical Decision&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;In case the reviewer requests substantial changes that involve a different technical approach, create a new commit to incorporate the new decision.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;p&gt;git add feature.txt&lt;br&gt;
git commit&lt;/p&gt;

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

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Minor Changes&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;For minor adjustments requested by the reviewer, you can amend the existing commit without changing the commit message:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;p&gt;git add feature.txt&lt;br&gt;
git commit &lt;span class="nt"&gt;--amend&lt;/span&gt; &lt;span class="nt"&gt;--no-edit&lt;/span&gt;&lt;/p&gt;

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

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Conclusion&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;In this SOP, we've outlined the CLEAN GIT principles for pushing local code changes to a remote repository. We've also covered how to handle reviewer-requested changes efficiently. In our next SOP, we'll explore how to apply CLEAN GIT principles to address hotfix requests in a production environment.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>programming</category>
      <category>git</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Clean Git: Self-Documented Project</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Wed, 06 Sep 2023 21:52:11 +0000</pubDate>
      <link>https://dev.to/rusydy/clean-git-self-documented-project-1efj</link>
      <guid>https://dev.to/rusydy/clean-git-self-documented-project-1efj</guid>
      <description>&lt;h2&gt;
  
  
  Why Should We Care About Git Commit Messages and PR Descriptions?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Real-world example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine this scenario: your team discovers a critical bug in your production environment. This bug is traced back to a change made by a developer who is no longer with the company. To resolve the issue, you need to adjust a SQL query file. The catch? You have no idea why this change was made in the first place. The commit message, PR description, ticket description, and even the code itself offer no clues. You're left scratching your head.&lt;/p&gt;

&lt;p&gt;The result? Countless hours spent deciphering the change and fixing the bug. However, if the commit message, PR description, ticket description, and code were well-documented, you could resolve the issue swiftly.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, What Makes a Good Commit Message and PR Description?
&lt;/h2&gt;

&lt;p&gt;While there's no rigid standard for good commit messages and PR descriptions, following these guidelines can significantly improve your documentation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Be Self-Documenting, Descriptive, and Concise&lt;/strong&gt;: Your commit message and PR description should explain the change without requiring readers to dive into the code. Clearly state the reason behind the change and the technical decisions involved in a brief and clear manner.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ideal Structure&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Commit Message&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="o"&gt;[&lt;/span&gt;branch-name]: &amp;lt;commit-message&amp;gt; Describe your changes briefly

&amp;lt;commit-description&amp;gt; Provide detailed information about the commit, including:
   &amp;lt;pre-commit-description&amp;gt; Explain the problem this commit addresses
   &amp;lt;commit-changes&amp;gt; Detail the changes made &lt;span class="k"&gt;in &lt;/span&gt;this commit
   &amp;lt;post-commit-description&amp;gt; Describe the impact of this commit


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&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%2F77ibq2aztgr3rnk393hg.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%2F77ibq2aztgr3rnk393hg.png" alt="Example of Commit Message" width="596" height="733"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PR Description&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="o"&gt;[&lt;/span&gt;branch-name]: &amp;lt;PR-title&amp;gt; Describe your changes briefly

&amp;lt;PR-description&amp;gt; Provide detailed information about the PR, including:
    &amp;lt;pre-PR-description&amp;gt; Explain the problem this PR addresses
    &amp;lt;PR-changes&amp;gt; Detail the changes made &lt;span class="k"&gt;in &lt;/span&gt;this PR
    &amp;lt;post-PR-description&amp;gt; Describe the impact of this PR


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

&lt;/div&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%2Fhsc1cumcfq9oogtddn9y.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%2Fhsc1cumcfq9oogtddn9y.png" alt="Example of PR Description" width="800" height="759"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Focus on a Single Aspect&lt;/strong&gt;: Each commit should centre on a single technical decision. If a change is linked to a ticket, the commit shouldn't include the ticket description, as that focuses on product and feature details, not the technical decision. Avoid duplicating code in the commit message, since the code is self-documenting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Squash Multiple Commits&lt;/strong&gt;: When multiple commits are required for a change, consolidate them into one commit before merging into the main branch. Update the commit message and PR description to reflect the change.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Split Multiple Changes&lt;/strong&gt;: If a ticket involves multiple changes, separate them into distinct commits. Each commit should address one technical decision, and accordingly, the commit message and PR description should be updated.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Incorporating these guidelines into your Git workflow will enhance clarity, save time, and make it easier to maintain your codebase.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>tutorial</category>
      <category>git</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Git Rebase: How to Handle Request for Changes to Specific Commits</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Sun, 19 Feb 2023 08:08:17 +0000</pubDate>
      <link>https://dev.to/rusydy/git-rebase-how-to-handle-changes-to-specific-commits-324m</link>
      <guid>https://dev.to/rusydy/git-rebase-how-to-handle-changes-to-specific-commits-324m</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;After completing my feature branch, I created a pull request to merge my changes into the master branch. However, I received feedback from a reviewer who suggested changes to my code. To address this, I need to make the following updates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In my pull request, there are three commits. For the second commit, I need to remove a few files and make substantial changes to one file.&lt;/li&gt;
&lt;li&gt;I also have to merge the third commit into the first commit, but I want to keep the second commit unchanged.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;first problem: Updating a Specific Commit&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Suppose we have three commits in our pull request, and we have to update the second commit by removing some files and making significant changes to one file.&lt;/p&gt;

&lt;p&gt;Here are the steps to address this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, make sure we are on the branch that contains the three commits. We can check this by running &lt;code&gt;git log&lt;/code&gt; and making sure we see all three commits listed.&lt;/li&gt;
&lt;li&gt;Next, run &lt;code&gt;git rebase -i HEAD~3&lt;/code&gt;. This will open an editor with the last three commits listed.&lt;/li&gt;
&lt;li&gt;Change the word &lt;code&gt;pick&lt;/code&gt; to &lt;code&gt;edit&lt;/code&gt; on the line that corresponds to the second commit. Save and close the editor.&lt;/li&gt;
&lt;li&gt;Git will then start the interactive rebase. It will stop at the second commit and give us a shell to work on. We can now make any changes we want to the second commit. When we are done, run &lt;code&gt;git add&lt;/code&gt; to add the changes to the staging area.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;git commit --amend&lt;/code&gt; to commit the changes to the second commit. We can change the commit message if we'd like to.&lt;/li&gt;
&lt;li&gt;Finally, use &lt;code&gt;git rebase --continue&lt;/code&gt; to resume the interactive rebase and apply the changes to the remaining commits.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This will leave we with three commits, but the second commit will have the changes we made.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;second problem: Merging Commits while Keeping One Untouched&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Suppose we also need to merge the third commit into the first commit, but we want to keep the second commit unchanged. Here are the steps to address this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Same as before, make sure we are on the branch that contains the three commits. We can check this by running &lt;code&gt;git log&lt;/code&gt; and making sure we see all three commits listed.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git rebase -i HEAD~3&lt;/code&gt;. This will open an editor with the last three commits listed.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the text editor, change the position of the third commit so that it's above the second commit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pick 1a2b3c4 First commit
pick 2a3b4c5 Second commit
pick 3a4b5c6 Third commit
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;becomes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pick 1a2b3c4 First commit
pick 3a4b5c6 Third commit
pick 2a3b4c5 Second commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Change the word &lt;code&gt;pick&lt;/code&gt; to &lt;code&gt;squash&lt;/code&gt; on the line that corresponds to the third commit.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pick 1a2b3c4 First commit
squash 3a4b5c6 Third commit
pick 2a3b4c5 Second commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save and close the editor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Git will combine the changes from the first and third commits into a single commit. We will be prompted to enter a new commit message for the merged commit. Edit the message as desired and save it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the merge commit message is saved, the interactive rebase process will complete and the new commit will be added to the repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The result will be two commits, the first with the changes from the first and third commits, and the second with the changes from the second commit.&lt;/p&gt;

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

&lt;p&gt;This is a compelling tool that can be used to change the history of our repository. It's important to understand how it works and how to use it properly. If we are not confident, we can always run &lt;code&gt;git reflog&lt;/code&gt; to see the history of our repository. This will show us the history of all the commits, even if they've been removed from the repository.&lt;/p&gt;

</description>
      <category>inclusion</category>
      <category>discuss</category>
      <category>career</category>
      <category>womenintech</category>
    </item>
    <item>
      <title>Introduction to Colima</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Thu, 09 Feb 2023 05:23:30 +0000</pubDate>
      <link>https://dev.to/rusydy/introduction-to-colima-kf0</link>
      <guid>https://dev.to/rusydy/introduction-to-colima-kf0</guid>
      <description>&lt;p&gt;Docker has become a popular tool for developers and sysadmins to manage and deploy applications. However, sometimes Docker may get stuck in the "starting" stage or the Docker daemon may not start, causing frustration for the users. In such cases, Colima can be a useful alternative. In this article, we will provide a step-by-step guide on how to install and start Colima.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Installing Colima&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To install Colima, we will use Homebrew, a package manager for macOS. If you don't have Homebrew installed, you can follow the instructions on the Homebrew website to install it.&lt;/p&gt;

&lt;p&gt;Once you have Homebrew installed, you can use the following command to install Colima:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

brew &lt;span class="nb"&gt;install &lt;/span&gt;colima


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

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Starting Colima&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After installing Colima, you can start it using the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

colima start


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

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Conclusion&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Colima is a useful alternative for users who are facing issues with Docker. It provides a simple and straightforward way to install and start applications. For more information, you can visit the Colima repository on GitHub at &lt;a href="https://github.com/abiosoft/colima" rel="noopener noreferrer"&gt;https://github.com/abiosoft/colima&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>docker</category>
    </item>
    <item>
      <title>Python Unittest for Beginners: How to use HTMLTestRunner to generate test reports</title>
      <dc:creator>Rusydy</dc:creator>
      <pubDate>Sun, 05 Feb 2023 20:58:10 +0000</pubDate>
      <link>https://dev.to/rusydy/python-unittest-for-beginners-how-to-use-htmltestrunner-to-generate-test-reports-21oa</link>
      <guid>https://dev.to/rusydy/python-unittest-for-beginners-how-to-use-htmltestrunner-to-generate-test-reports-21oa</guid>
      <description>&lt;p&gt;In this article, we will go over the process of generating test reports using the &lt;code&gt;unittest&lt;/code&gt; framework in Python. We will use the &lt;code&gt;HTMLTestRunner&lt;/code&gt; library to generate HTML reports for our tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup HTMLTestRunner
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;HTMLTestRunner&lt;/code&gt; library is a third-party library that extends the &lt;code&gt;unittest&lt;/code&gt; framework to generate HTML reports for our tests. It is available on &lt;a href="https://github.com/findyou/HTMLTestRunnerCN/blob/master/python3x/HTMLTestReportEN.py" rel="noopener noreferrer"&gt;GitHub-findyou&lt;/a&gt; or &lt;a href="https://github.com/Rusydy/selenium-learn/blob/main/HTMLTestRunner/HTMLTestRunner.py" rel="noopener noreferrer"&gt;GitHub-Rusydy&lt;/a&gt;. Just download or copy-paste the file and put it in the same directory as your test file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using HTMLTestRunner
&lt;/h2&gt;

&lt;p&gt;To use HTMLTestRunner to create an HTML report for your tests, you need to write your test cases using the unittest library, and then use HTMLTestRunner to run your test cases and generate the HTML report. Here's an example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;initiate a test case class that inherits from &lt;code&gt;unittest.TestCase&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyTestCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unittest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TestCase&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;setUp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;tearDown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;testCase1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assertEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;testError&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# The following test case will fail
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;testCase2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assertEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;testError&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;testCase3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assertEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;测试错误&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# en: test error
&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;testCase4&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assertEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;测试错误&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# The upper test case will fail
&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;testCase5&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;create a test suite and add the test cases to the test suite
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# 添加Suite, en: add Suite
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;Suite&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;

    &lt;span class="c1"&gt;#定义一个单元测试容器, en: define a unit test container
&lt;/span&gt;    &lt;span class="n"&gt;suiteTest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;unittest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TestSuite&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;#将测试用例加入到容器, en: add test cases to the container
&lt;/span&gt;    &lt;span class="n"&gt;suiteTest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addTest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyTestCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;testCase1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;suiteTest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addTest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyTestCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;testCase2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;suiteTest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addTest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyTestCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;testCase3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;suiteTest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addTest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyTestCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;testCase4&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;suiteTest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addTest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyTestCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;testCase5&lt;/span&gt;&lt;span class="sh"&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;suiteTest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;run the test suite using HTMLTestRunner
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;test_report.html&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;w&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
        &lt;span class="n"&gt;runner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;HTMLTestRunner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HTMLTestRunner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="c1"&gt;# type: ignore
&lt;/span&gt;            &lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
            &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;测试报告&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# en: test report
&lt;/span&gt;            &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;测试报告&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# en: test report
&lt;/span&gt;        &lt;span class="n"&gt;unittest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;testRunner&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;runner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;run the test file and generate the HTML report
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 test_file.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace "test_file.py" with the actual name of your test file. After running the tests, the HTML report will be generated in the same directory with the file name "test_report.html". You can open the report in any web browser to view the test results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this article, we showed you how to set up and use HTMLTestRunner to generate HTML reports for your unit tests. HTMLTestRunner is a useful tool that makes it easy to view the results of your tests in a clear and organized way. By using HTMLTestRunner, you can quickly and easily see which tests passed and which failed, and get a more profound understanding of the overall status of your tests. The full code on this page can be found on &lt;a href="https://github.com/Rusydy/selenium-learn/tree/main/HTMLTestRunner" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Q&amp;amp;A&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Q: What is the difference between HTMLTestRunner and unittest?&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A: HTMLTestRunner is a third-party library that extends the unittest framework to generate HTML reports for your tests. It is not part of the standard library.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Q: What is setUp and tearDown in unittest?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A: The setUp and tearDown methods are used to set up and tear down the test environment. The setUp method is called before each test case is executed, and the tearDown method is called after each test case is executed. You can use the setUp and tearDown methods to set up and tear down the test environment, such as creating a test database, creating a test user, or creating a test file. More information about setUp and tearDown can be found in the &lt;a href="https://docs.python.org/3.7/library/unittest.html#setupclass-and-teardownclass" rel="noopener noreferrer"&gt;unittest documentation&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devto</category>
      <category>announcement</category>
      <category>offers</category>
    </item>
  </channel>
</rss>
