<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Aaron Shenny's Coding Journey]]></title><description><![CDATA[Here you can see my stories and journeys.]]></description><link>https://monocroto.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 10:41:31 GMT</lastBuildDate><atom:link href="https://monocroto.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[GO | Simple Calculator Project]]></title><description><![CDATA[So, i came to know about this new programming language called Golang, shorten as Go. It was designed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson, and publicly announced in November of 2009. It is known for the simplicity of its ...]]></description><link>https://monocroto.hashnode.dev/go-simple-calculator-project</link><guid isPermaLink="true">https://monocroto.hashnode.dev/go-simple-calculator-project</guid><category><![CDATA[aaronshenny]]></category><category><![CDATA[Go Language]]></category><dc:creator><![CDATA[Aaron Shenny]]></dc:creator><pubDate>Mon, 05 May 2025 06:16:07 GMT</pubDate><content:encoded><![CDATA[<p>So, i came to know about this new programming language called Golang, shorten as Go. It was designed at <a target="_blank" href="https://en.wikipedia.org/wiki/Google">Google</a> in 2007 by <a target="_blank" href="https://en.wikipedia.org/wiki/Robert_Griesemer">Robert Griesemer</a>, <a target="_blank" href="https://en.wikipedia.org/wiki/Rob_Pike">Rob Pike</a>, and <a target="_blank" href="https://en.wikipedia.org/wiki/Ken_Thompson">Ken Thompson</a>, and publicly announced in November of 2009. It is known for the simplicity of its syntax and the efficiency of development that it enables by the inclusion of a large standard library supplying many needs for common projects.</p>
<p>It dosent have the same number of packages as python. But it does shows the its potential to reach above Python or any other programming languages. One thing i noticed when i was working with it, is that it does shows errors or logic errors (sometimes) at the time of saving the file. Cause Go is a complied language. So before running the program, 99% of errors will be solved.</p>
<p>What about the structure? What’s the code organization?</p>
<h2 id="heading-code-organizationhttpsgodevdoccodeorganization-from-godev">Code organization<a target="_blank" href="https://go.dev/doc/code#Organization">¶</a> (From Go.dev)</h2>
<p>Go programs are organized into packages. A package is a collection of source files in the same directory that are compiled together. Functions, types, variables, and constants defined in one source file are visible to all other source files within the same package.</p>
<p>A repository contains one or more modules. A module is a collection of related Go packages that are released together. A Go repository typically contains only one module, located at the root of the repository. A file named <code>go.mod</code> there declares the module path: the import path prefix for all packages within the module. The module contains the packages in the directory containing its <code>go.mod</code> file as well as subdirectories of that directory, up to the next subdirectory containing another <code>go.mod</code> file (if any).</p>
<p>Note that you don't need to publish your code to a remote repository before you can build it. A module can be defined locally without belonging to a repository. However, it's a good habit to organize your code as if you will publish it someday.</p>
<p>Each module's path not only serves as an import path prefix for its packages, but also indicates where the <code>go</code> command should look to download it. For example, in order to download the module <code>golang.org/x/tools</code>, the <code>go</code> command would consult the repository indicated by <code>https://golang.org/x/tools</code> (described more <a target="_blank" href="https://go.dev/cmd/go/#hdr-Remote_import_paths">here</a>).</p>
<p>An import path is a string used to import a package. A package's import path is its module path joined with its subdirectory within the module. For example, the module <code>github.com/google/go-cmp</code> contains a package in the directory <code>cmp/</code>. That package's import path is <code>github.com/google/go-cmp/cmp</code>. Packages in the standard library do not have a module path prefix.</p>
<h2 id="heading-to-simplify">To simplify;</h2>
<h3 id="heading-packages">🧱 <strong>Packages</strong></h3>
<ul>
<li><p>A <strong>package</strong> is a folder with <code>.go</code> files.</p>
</li>
<li><p>Files in the same package can use each other's functions.</p>
</li>
<li><p>Example:<br />  <code>mathutils/add.go</code> and <code>mathutils/subtract.go</code> are in the same package.</p>
</li>
</ul>
<hr />
<h3 id="heading-modules">📦 <strong>Modules</strong></h3>
<ul>
<li><p>A <strong>module</strong> is your whole Go project.</p>
</li>
<li><p>It can contain many packages (folders).</p>
</li>
<li><p>You create a module with:<br />  <code>go mod init [module-name]</code></p>
</li>
<li><p>This creates a <code>go.mod</code> file at the root.</p>
</li>
</ul>
<hr />
<h3 id="heading-import-paths">🔗 <strong>Import Paths</strong></h3>
<ul>
<li><p>To use a package, you import it with a <strong>path</strong>.</p>
</li>
<li><p>If your module is called <a target="_blank" href="http://github.com/you/myapp"><code>github.com/you/myapp</code></a>, and you have a folder <code>mathutils</code>, the import looks like:</p>
<pre><code class="lang-go">  goCopy codeimport <span class="hljs-string">"github.com/you/myapp/mathutils"</span>
</code></pre>
</li>
<li><p>For built-in packages like <code>fmt</code>, just write:</p>
<pre><code class="lang-go">  goCopy codeimport <span class="hljs-string">"fmt"</span>
</code></pre>
</li>
</ul>
<hr />
<h3 id="heading-key-points">💡 Key Points</h3>
<ul>
<li><p>Packages = folders of code.</p>
</li>
<li><p>Module = your project with <code>go.mod</code>.</p>
</li>
<li><p>You can build and run locally — no need for GitHub.</p>
</li>
<li><p>Import paths tell Go where to find code</p>
</li>
</ul>
<p>Thanks to ChatGPT for the simplification.</p>
<h1 id="heading-what-makes-go-different">What makes GO different?</h1>
<h3 id="heading-1-simplicity-and-minimalism">1. <strong>Simplicity and Minimalism</strong></h3>
<ul>
<li><p>Go has a small, clean standard library and very few keywords.</p>
</li>
<li><p>There's <em>one</em> way to do most things — a stark contrast to languages like Python or Ruby.</p>
</li>
<li><p>Avoids complex features like inheritance, generics (until recently), or macros.</p>
</li>
</ul>
<hr />
<h3 id="heading-2-built-in-concurrency">2. <strong>Built-in Concurrency</strong></h3>
<ul>
<li><p>Go was designed for modern multicore systems.</p>
</li>
<li><p>It has <strong>goroutines</strong> (lightweight threads) and <strong>channels</strong> for safe, easy-to-use concurrency.</p>
</li>
<li><p>Its concurrency model is based on CSP (Communicating Sequential Processes), which is elegant and scalable.</p>
</li>
</ul>
<hr />
<h3 id="heading-3-compiled-fast-and-efficient">3. <strong>Compiled, Fast, and Efficient</strong></h3>
<ul>
<li><p>Go is statically typed and compiled to native machine code.</p>
</li>
<li><p>Fast compilation times compared to C++ or Java.</p>
</li>
<li><p>Produces a single binary with no external dependencies by default.</p>
</li>
</ul>
<hr />
<h3 id="heading-4-garbage-collected">4. <strong>Garbage Collected</strong></h3>
<ul>
<li><p>Unlike C or C++, Go has automatic memory management.</p>
</li>
<li><p>Offers a good balance between control and safety.</p>
</li>
</ul>
<hr />
<p>So i learned some basics of go and done small simple calculator project. I felt easy and more defined way to code. Maybe i will learn more.</p>
<h2 id="heading-simple-calculator-project">Simple calculator Project</h2>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> (
    <span class="hljs-string">"fmt"</span>
)
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">Addition</span><span class="hljs-params">(num1 <span class="hljs-keyword">int</span>,num2 <span class="hljs-keyword">int</span>)</span>  <span class="hljs-title">int</span></span> {
    <span class="hljs-keyword">var</span> sum <span class="hljs-keyword">int</span>
    sum = num1 + num2
    <span class="hljs-keyword">return</span> sum
}
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">Subtration</span><span class="hljs-params">(num1 <span class="hljs-keyword">int</span>,num2 <span class="hljs-keyword">int</span>)</span>  <span class="hljs-title">int</span></span> {
    <span class="hljs-keyword">var</span> sub <span class="hljs-keyword">int</span>
    sub = num1 - num2
    <span class="hljs-keyword">return</span> sub
}
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span>  {
    fmt.Println(<span class="hljs-string">"Simple maths calculator"</span>)
    fmt.Println(<span class="hljs-string">"1. Addition\n2. Subtration\n3. Multiplication\n4. Division"</span>)
    <span class="hljs-keyword">for</span>{
        <span class="hljs-built_in">print</span>(<span class="hljs-string">"Choice? : "</span>)
        <span class="hljs-keyword">var</span> ch <span class="hljs-keyword">int</span>
        fmt.Scan(&amp;ch)
        <span class="hljs-keyword">if</span> ch==<span class="hljs-number">1</span>{
            <span class="hljs-keyword">var</span> num1, num2 <span class="hljs-keyword">int</span>
            fmt.Println(<span class="hljs-string">"Enter 1st number:"</span>)
            fmt.Scan(&amp;num1)
            fmt.Println(<span class="hljs-string">"Enter 2nd number:"</span>)
            fmt.Scan(&amp;num2)
            sum := Addition(num1, num2)
            fmt.Println(<span class="hljs-string">"Sum is: "</span>, sum)

        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ch == <span class="hljs-number">2</span>{
            <span class="hljs-keyword">var</span> num1, num2 <span class="hljs-keyword">int</span>
            fmt.Println(<span class="hljs-string">"Enter 1st number:"</span>)
            fmt.Scan(&amp;num1)
            fmt.Println(<span class="hljs-string">"Enter 2nd number:"</span>)
            fmt.Scan(&amp;num2)
            sub := Subtration(num1, num2)
            fmt.Println(<span class="hljs-string">"Subtration is: "</span>, sub)
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ch == <span class="hljs-number">3</span>{
            <span class="hljs-keyword">var</span> num1, num2 <span class="hljs-keyword">int</span>
            fmt.Println(<span class="hljs-string">"Enter 1st number:"</span>)
            fmt.Scan(&amp;num1)
            fmt.Println(<span class="hljs-string">"Enter 2nd number:"</span>)
            fmt.Scan(&amp;num2)
            mul := num1 * num2
            fmt.Println(<span class="hljs-string">"Multiplication is: "</span>, mul)
        }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ch == <span class="hljs-number">4</span>{
            <span class="hljs-keyword">var</span> num1, num2 <span class="hljs-keyword">int</span>
            fmt.Println(<span class="hljs-string">"Enter 1st number:"</span>)
            fmt.Scan(&amp;num1)
            fmt.Println(<span class="hljs-string">"Enter 2nd number:"</span>)
            fmt.Scan(&amp;num2)
            div := num1 / num2
            fmt.Println(<span class="hljs-string">"Division is: "</span>, div)
        }<span class="hljs-keyword">else</span>{
            <span class="hljs-built_in">print</span>(<span class="hljs-string">"Invalid choice"</span>)
            <span class="hljs-keyword">break</span>
        }
    }
}
</code></pre>
<p>Thanks! Go coding!</p>
]]></content:encoded></item></channel></rss>