<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Clean Code on Lorbic</title><link>http://localhost:1313/categories/clean-code/</link><description>Recent content in Clean Code on Lorbic</description><generator>Hugo</generator><language>en</language><lastBuildDate>Tue, 11 Mar 2025 09:32:00 +0000</lastBuildDate><atom:link href="http://localhost:1313/categories/clean-code/index.xml" rel="self" type="application/rss+xml"/><item><title>Testing Types</title><link>http://localhost:1313/testing-types/</link><pubDate>Tue, 11 Mar 2025 09:32:00 +0000</pubDate><guid>http://localhost:1313/testing-types/</guid><description>&lt;p>Understanding different types of software testing is crucial for delivering a reliable application. Smoke Testing checks basic stability after a new build, while Sanity Testing verifies specific bug fixes or minor updates. Functional Testing ensures that features work as expected based on business requirements. Regression Testing prevents new changes from breaking existing functionality. End-to-End (E2E) Testing simulates real-world user workflows, and Performance Testing checks system speed, load handling capacity, and responsiveness. Implementing these (some or all) test types helps maintain software quality and prevent critical failures.&lt;/p></description></item><item><title>Go Clean Code Guidelines</title><link>http://localhost:1313/go-clean-code-guidelines/</link><pubDate>Sun, 22 Sep 2024 15:22:00 +0000</pubDate><guid>http://localhost:1313/go-clean-code-guidelines/</guid><description>&lt;h3 id="go-clean-code-guidelines-for-code-quality-and-maintainability">Go Clean Code Guidelines for Code Quality and Maintainability.&lt;a class="anchorjs-link" href="#go-clean-code-guidelines-for-code-quality-and-maintainability" aria-label="Link to section: Go Clean Code Guidelines for Code Quality and Maintainability.">&lt;/a>&lt;/h3>&lt;p>When it comes to writing clean, maintainable code, there are a few fundamental rules that can help improve the overall structure and quality of your codebase. As engineers, our goal should be to keep things simple, clear, and scalable. With this in mind, here are some guidelines which prioritize code readability, functional clarity, and the overall maintainability of a project.
These guidelines are based on principles from clean code, SOLID, and functional programming while emphasizing simplicity over unnecessary complexity.&lt;/p></description></item><item><title>SOLID and Functional Programming Principles in Go</title><link>http://localhost:1313/solid-and-functional-programming-principles-in-go/</link><pubDate>Sun, 22 Sep 2024 00:03:00 +0000</pubDate><guid>http://localhost:1313/solid-and-functional-programming-principles-in-go/</guid><description>&lt;p>Let&amp;rsquo;s go through the &lt;strong>SOLID principles&lt;/strong> and &lt;strong>functional programming principles&lt;/strong> that can apply to your Go codebase. I&amp;rsquo;ll provide simple Go examples along with brief explanations to show how each principle can improve code quality.&lt;/p>
&lt;hr>
&lt;h3 id="solid-principles">&lt;strong>SOLID Principles&lt;/strong>&lt;a class="anchorjs-link" href="#solid-principles" aria-label="Link to section: SOLID Principles">&lt;/a>&lt;/h3>&lt;ol>
&lt;li>
&lt;p>&lt;strong>S&lt;/strong>ingle Responsibility Principle (SRP)&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Description:&lt;/strong> A class or function should have only one reason to change, meaning it should only have one job or responsibility.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Example:&lt;/strong>&lt;/p>
&lt;div class="code-block">
 &lt;div class="code-header">
 &lt;div class="header-left">
 &lt;span class="code-lang">go&lt;/span>
 &lt;/div>
 &lt;div class="header-right">
 &lt;button class="wrap-code-button" title="Toggle line wrap" aria-label="Toggle line wrap">
 &lt;svg class="svg-icon " aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">&lt;path d="M448 256c0-53-43-96-96-96H96c-17.7 0-32 14.3-32 32s14.3 32 32 32h256c17.7 0 32 14.3 32 32s-14.3 32-32 32H165.5l37.3-37.3c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-96 96c-12.5 12.5-12.5 32.8 0 45.3l96 96c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L165.5 352H352c53 0 96-43 96-96zM32 64C14.3 64 0 78.3 0 96s14.3 32 32 32H480c17.7 0 32-14.3 32-32s-14.3-32-32-32H32zM32 384c-17.7 0-32 14.3-32 32s14.3 32 32 32H256c17.7 0 32-14.3 32-32s-14.3-32-32-32H32z"/>&lt;/svg>

 &lt;/button>
 &lt;button class="download-code-button" data-lang="go" title="Download Code" aria-label="Download Code">
 &lt;svg class="svg-icon " aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">&lt;path d="M288 32c0-17.7-14.3-32-32-32s-32 14.3-32 32V274.7l-73.4-73.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l128 128c12.5 12.5 32.8 12.5 45.3 0l128-128c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L288 274.7V32zM64 352c-35.3 0-64 28.7-64 64v32c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V416c0-35.3-28.7-64-64-64H346.5l-45.3 45.3c-25 25-65.5 25-90.5 0L165.5 352H64zm368 56a24 24 0 1 1 0 48 24 24 0 1 1 0-48z"/>&lt;/svg>

 &lt;/button>
 &lt;button class="copy-code-button" title="Copy Code" aria-label="Copy Code">
 &lt;svg class="svg-icon " aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">&lt;!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. -->&lt;path d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/>&lt;/svg>
 &lt;/button>
 &lt;/div>
 &lt;/div>
 &lt;div class="code-body">&lt;div class="highlight">&lt;pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 1&lt;/span>&lt;span>&lt;span style="color:#8b949e;font-style:italic">// Good: Separate responsibilities into two functions&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 2&lt;/span>&lt;span>&lt;span style="color:#ff7b72">type&lt;/span> EmailSender &lt;span style="color:#ff7b72">struct&lt;/span>{}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 3&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 4&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 5&lt;/span>&lt;span>&lt;span style="color:#ff7b72">func&lt;/span> (e &lt;span style="color:#ff7b72;font-weight:bold">*&lt;/span>EmailSender) &lt;span style="color:#d2a8ff;font-weight:bold">SendEmail&lt;/span>(to, subject, body &lt;span style="color:#ff7b72">string&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 6&lt;/span>&lt;span> &lt;span style="color:#8b949e;font-style:italic">// logic for sending email&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 7&lt;/span>&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 8&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681"> 9&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">10&lt;/span>&lt;span>&lt;span style="color:#ff7b72">func&lt;/span> &lt;span style="color:#d2a8ff;font-weight:bold">formatEmailBody&lt;/span>(template &lt;span style="color:#ff7b72">string&lt;/span>, data &lt;span style="color:#ff7b72">map&lt;/span>[&lt;span style="color:#ff7b72">string&lt;/span>]&lt;span style="color:#ff7b72">string&lt;/span>) &lt;span style="color:#ff7b72">string&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">11&lt;/span>&lt;span> &lt;span style="color:#8b949e;font-style:italic">// logic for formatting the email body&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">12&lt;/span>&lt;span> &lt;span style="color:#ff7b72">return&lt;/span> &lt;span style="color:#a5d6ff">&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">13&lt;/span>&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">14&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">15&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">16&lt;/span>&lt;span>&lt;span style="color:#8b949e;font-style:italic">// Avoid: Single function doing multiple jobs&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">17&lt;/span>&lt;span>&lt;span style="color:#ff7b72">func&lt;/span> &lt;span style="color:#d2a8ff;font-weight:bold">sendFormattedEmail&lt;/span>(to, subject, template &lt;span style="color:#ff7b72">string&lt;/span>, data &lt;span style="color:#ff7b72">map&lt;/span>[&lt;span style="color:#ff7b72">string&lt;/span>]&lt;span style="color:#ff7b72">string&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">18&lt;/span>&lt;span> body &lt;span style="color:#ff7b72;font-weight:bold">:=&lt;/span> &lt;span style="color:#d2a8ff;font-weight:bold">formatEmailBody&lt;/span>(template, data)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">19&lt;/span>&lt;span> &lt;span style="color:#8b949e;font-style:italic">// email sending logic mixed with formatting&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6e7681">20&lt;/span>&lt;span>}&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/div>
&lt;/div>&lt;/li>
&lt;/ol>
&lt;hr>
&lt;ol start="2">
&lt;li>
&lt;p>&lt;strong>O&lt;/strong>pen/Closed Principle (OCP)&lt;/p></description></item></channel></rss>