<?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[Programming, System Design and AI | Latencot]]></title><description><![CDATA[Here, you will read all about tech and tech updates. From writing code to building AI systems, we'll talk and share about everything.]]></description><link>https://tech.latencot.com</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1747026831088/47aa11c9-62a8-493d-9ff0-63723a50d5e6.png</url><title>Programming, System Design and AI | Latencot</title><link>https://tech.latencot.com</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 00:45:03 GMT</lastBuildDate><atom:link href="https://tech.latencot.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Array vs Slice in Golang]]></title><description><![CDATA[Arrays
Golang is statically typed compiled language. So it can be compared with languages such as C++. Now, C++ has arrays however those were not with dynamic length. However we also have collections using which can make dynamic arrays.
Similarly, in...]]></description><link>https://tech.latencot.com/array-vs-slice-in-golang</link><guid isPermaLink="true">https://tech.latencot.com/array-vs-slice-in-golang</guid><category><![CDATA[make in go]]></category><category><![CDATA[golang]]></category><category><![CDATA[Go Language]]></category><category><![CDATA[array-slice-in-go]]></category><category><![CDATA[dynamic arrays]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Thu, 05 Jun 2025 05:31:35 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-arrays">Arrays</h2>
<p>Golang is statically typed compiled language. So it can be compared with languages such as C++. Now, C++ has arrays however those were not with dynamic length. However we also have collections using which can make dynamic arrays.</p>
<p>Similarly, in Golang, an array has a static length.</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> myArr = [<span class="hljs-number">3</span>]<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
</code></pre>
<p>In the above example, we have created an array with 3 elements. The basic syntax of creating an array is:</p>
<pre><code class="lang-go">[length]datatype{element1, element2, element3...}
</code></pre>
<p>You can define arrays in following ways</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> myArr = [<span class="hljs-number">4</span>]<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>}                <span class="hljs-comment">//fixed length</span>
<span class="hljs-keyword">var</span> myArr2 = [...]<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>}          <span class="hljs-comment">//fixed length but dynamic length calculation</span>
<span class="hljs-keyword">var</span> myArr2 = [<span class="hljs-number">8</span>]<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>}               <span class="hljs-comment">//next 4 values will be zero</span>
<span class="hljs-keyword">var</span> myArr2 = [<span class="hljs-number">5</span>]<span class="hljs-keyword">string</span>{<span class="hljs-string">"I"</span>, <span class="hljs-string">"am"</span>, <span class="hljs-string">"awesome"</span>}  <span class="hljs-comment">//next 2 values will be empty strings ""</span>
<span class="hljs-keyword">var</span> myArr2 = [<span class="hljs-number">2</span>]<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>}               <span class="hljs-comment">//this will cause an error</span>
</code></pre>
<p>Let’s create one more array</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> myArr = [<span class="hljs-number">8</span>]<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>}
</code></pre>
<p>In the above example, we have created an array of length 8 however we have added only 4 elements in it. The other 4 elements in this case will be zero because the type is int. For strings, the zero value is ““. For pointers the zero value is nil.</p>
<p>We can index those elements and change the values. Accessing values is similar to other programming languages, using indexes. Arrays are 0-indexed.</p>
<pre><code class="lang-go">myArr[<span class="hljs-number">4</span>] = <span class="hljs-number">5</span>
myArr[<span class="hljs-number">5</span>] = <span class="hljs-number">6</span>
myArr[<span class="hljs-number">6</span>] = <span class="hljs-number">7</span>
myArr[<span class="hljs-number">7</span>] = <span class="hljs-number">8</span>
</code></pre>
<p>Slices in simple words are dynamic arrays. Slices provide you with modularity over arrays. Creating a slice is similar to creating an array. You just don't provide the length of the array.</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> myArr []<span class="hljs-keyword">int</span> = []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
myArr2 := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>}
fmt.Println(myArr)
fmt.Println(<span class="hljs-built_in">len</span>(myArr2))
fmt.Println(<span class="hljs-built_in">cap</span>(myArr2))
</code></pre>
<p>In the above example, you can see the cap function which returns the capacity that the slice can hold currently as per the memory alloted to it. This as well is dynamic and grows with the length of the array.</p>
<p>To append values to a slice, you can use the append function as follows:</p>
<pre><code class="lang-go">arr := []<span class="hljs-keyword">int</span>(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>)
arr = <span class="hljs-built_in">append</span>(arr, <span class="hljs-number">5</span>)
</code></pre>
<p>Below are some more examples</p>
<pre><code class="lang-go">arr := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>}
fmt.Println(arr, <span class="hljs-built_in">len</span>(arr), <span class="hljs-built_in">cap</span>(arr))
arr = <span class="hljs-built_in">append</span>(arr, <span class="hljs-number">5</span>)
fmt.Println(arr, <span class="hljs-built_in">len</span>(arr), <span class="hljs-built_in">cap</span>(arr))
arr2 := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
fmt.Println(arr2, <span class="hljs-built_in">len</span>(arr2), <span class="hljs-built_in">cap</span>(arr2))
arr2 = <span class="hljs-built_in">append</span>(arr2, <span class="hljs-number">4</span>) <span class="hljs-comment">// Capacity changes to 6 (2x)</span>
<span class="hljs-comment">// arr2 = append(arr2, 4, 5)             // Capacity changes to 6 (2x)</span>
<span class="hljs-comment">// arr2 = append(arr2, 4, 5, 6)          // Capacity changes to 6 (2x)</span>
<span class="hljs-comment">// arr2 = append(arr2, 4, 5, 6, 7)       // Capacity changes to 8 (2x + 2)</span>
<span class="hljs-comment">// arr2 = append(arr2, 4, 5, 6, 7, 8, 9) // Capacity changes to 8 (2x + 2 + 2)</span>
fmt.Println(arr2, <span class="hljs-built_in">len</span>(arr2), <span class="hljs-built_in">cap</span>(arr2))
fmt.Println(arr2, <span class="hljs-built_in">len</span>(arr2), <span class="hljs-built_in">cap</span>(arr2))
</code></pre>
<p>In the above examples, I noticed one thing. When you append to an array for which the length and capacity are equal, it doubles the capacity of the array.</p>
<p>When the elements that are being added are more than the current length of the array and the length and capacity are equal, the capacity is incremented in a different way.</p>
<p>If the length and capacity of array is 3, and you are adding 6 elements, so the final length of array will be 9.</p>
<p>But capacity will be incremented as follows:</p>
<ol>
<li><p>First it will double the capacity. so 3 becomes 6.</p>
</li>
<li><p>Can 9 elements fit in the capacity of 6, no... Hence now the capacity is further increased by 2 so the new capacity becomes 8.</p>
</li>
<li><p>Can 9 elements fit in the capacity of 8, no... hence now the capacity is further increased by 2 so the new capacity becomes 10.</p>
</li>
<li><p>Can 9 elements fit in the capacity of 10, yes. So this is the final capacity.</p>
</li>
</ol>
<p>I observed that capacity first increases by 2 x original capacity and then is incremented by 2.</p>
<p>But once the append operation is done, and the length has gone from 3 to 9 and the capacity has become 10, if you now append again but just one value, then the capacity remains 10 and length becomes 10.</p>
<p>However instead of one value, if you increment 2 values, the length becomes 11, which cannot fit in the capacity of 10. So now the capacity is first doubled again from 10 to 20.</p>
<p>So the new length will be 11 and the new capacity will be 20.</p>
<h3 id="heading-adding-slice-to-slice">Adding Slice to Slice</h3>
<pre><code class="lang-go">arr2 = <span class="hljs-built_in">append</span>(arr2, arr...) <span class="hljs-comment">//adding slice to another slice</span>
fmt.Println(arr2, <span class="hljs-built_in">len</span>(arr2), <span class="hljs-built_in">cap</span>(arr2))
</code></pre>
<p>The above example shows how you can add a slice to a slice using the <code>...</code> operator.</p>
<h3 id="heading-slicing-a-slice">Slicing a Slice</h3>
<pre><code class="lang-go">arr3 := arr2[<span class="hljs-number">5</span>:<span class="hljs-number">7</span>]
<span class="hljs-comment">// arr3 := arr2[:7] // will slice from start upto 7</span>
<span class="hljs-comment">// arr3 := arr2[5:] // will slice from 5 till end</span>
<span class="hljs-comment">// arr3 := arr2[:] // will slice from start to end</span>
fmt.Println(arr, arr2, arr3)
arr3[<span class="hljs-number">1</span>] = <span class="hljs-number">25</span> <span class="hljs-comment">//Updates original array (arr2) as well but (arr) won't change</span>
fmt.Println(arr, arr2, arr3)
</code></pre>
<p>In the above example, we created a shorter version of the slice from index 5 to 7(not inclusive of 7). However the arr3 elements have the same reference as of arr2 and hence when you make any change in arr3, arr2 gets affected.</p>
<pre><code class="lang-go">arr3 = <span class="hljs-built_in">append</span>(arr3, <span class="hljs-number">82</span>, <span class="hljs-number">83</span>, <span class="hljs-number">84</span>)
fmt.Println(arr, arr2, arr3)
</code></pre>
<p>If you further append into arr3 like above, the effect will be as follows</p>
<ol>
<li>The length of arr2 is 9 while arr3 is indexed from 5th upto 7th index of arr2. The length of the arr3 is 2 but the capacity is 7 because you sliced upto 7 even though you took only 2 elements. The memory referencing will be as follows</li>
</ol>
<pre><code class="lang-go">mem  <span class="hljs-number">0</span>  <span class="hljs-number">1</span>  <span class="hljs-number">2</span>  <span class="hljs-number">3</span>  <span class="hljs-number">4</span>  <span class="hljs-number">5</span>  <span class="hljs-number">6</span>  <span class="hljs-number">7</span>  <span class="hljs-number">8</span>  <span class="hljs-number">9</span>  <span class="hljs-number">10</span>
arr2 <span class="hljs-number">1</span>  <span class="hljs-number">2</span>  <span class="hljs-number">3</span>  <span class="hljs-number">4</span>  <span class="hljs-number">1</span>  <span class="hljs-number">2</span>  <span class="hljs-number">25</span> <span class="hljs-number">4</span>  <span class="hljs-number">5</span>
arr3                <span class="hljs-number">2</span>  <span class="hljs-number">25</span> -  -  -  -  -
</code></pre>
<ol start="2">
<li><p>In the above example, the <code>-</code> represents memory reserved for arr3 elements. So you can notice that the memory reservation also starts from the 5th index of arr2. So basically for arr3, the index 7 and 8 of arr2 are actually reserved for arr3 but empty in arr3's perspective. But for arr2, those actually hold values.</p>
</li>
<li><p>When you append 3 elements 82, 83 and 84... 82 and 83 take the 7th and 8th index of arr2 so the 7th and 8th index of arr2 are updated as well</p>
</li>
<li><p>Now arr3 has memory reserved beyond the memory of arr2. So 84 takes next position to 83. But since arr2 does not have that memory reserved for itself, 84 does not reflect in arr2.</p>
</li>
</ol>
<p>So the initial and final state of arr2 and arr3 will be:</p>
<pre><code class="lang-go">initial
arr2 = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">25</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
arr3 = [<span class="hljs-number">2</span>, <span class="hljs-number">25</span>]

Final
arr2 = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">25</span>, <span class="hljs-number">82</span>, <span class="hljs-number">83</span>]
arr3 = [<span class="hljs-number">2</span>, <span class="hljs-number">25</span>, <span class="hljs-number">82</span>, <span class="hljs-number">83</span>, <span class="hljs-number">84</span>]
</code></pre>
<h3 id="heading-copying-a-slice">Copying a slice</h3>
<p>If you wish that the above should not happen, then you can copy slices with their memory addresses as well using the copy function.</p>
<pre><code class="lang-go">myarr1 := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>}
myarr2 := myarr1[<span class="hljs-number">5</span>:<span class="hljs-number">7</span>]
<span class="hljs-keyword">var</span> myarr2Copy = <span class="hljs-built_in">make</span>([]<span class="hljs-keyword">int</span>, <span class="hljs-built_in">len</span>(myarr2))
<span class="hljs-built_in">copy</span>(myarr2Copy, myarr2)
</code></pre>
<p>Here we used 2 functions, make and copy. We will discuss more about make later. But for now, make is a way to declare variables as well as allows to declare the length and capacity as well.</p>
<p>We declared a <code>myarr2Copy</code> variable which has same length as of myarr2. Then we used the copy function to copy values from <code>myarr2</code> to <code>myarr2Copy</code>. Since we have already declared the <code>myarr2Copy</code> variable, it's address will be different as of <code>myarr2</code> or <code>myarr1</code>.</p>
<p>So now if you append to <code>myarr2Copy</code></p>
<pre><code class="lang-go">fmt.Println(myarr2Copy, myarr2, myarr1)
myarr2Copy = <span class="hljs-built_in">append</span>(myarr2Copy, <span class="hljs-number">9</span>, <span class="hljs-number">10</span>, <span class="hljs-number">11</span>)
fmt.Println(myarr2Copy, myarr2, myarr1)
</code></pre>
<p>This should not update myarr2 or myarr1 and only myarr2Copy will be appended.</p>
<h2 id="heading-make-function">Make Function</h2>
<p>Make function let's you declare variables just like var. There are some differences though. Make function has 3 parameters</p>
<pre><code class="lang-go"><span class="hljs-built_in">make</span>(<span class="hljs-keyword">type</span>, length, capacity)
</code></pre>
<p>The type is the data type to be declared, the length and capacity can be passed in case of slices while for other types, length and capacity is not needed.</p>
<p>Make does not work for primitive types like bool, int and string, but works for slices, struct and map.</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> x []<span class="hljs-keyword">int</span>
x[<span class="hljs-number">0</span>] = <span class="hljs-number">10</span> <span class="hljs-comment">//this will cause an error</span>

x := <span class="hljs-built_in">make</span>([]<span class="hljs-keyword">int</span>, <span class="hljs-number">4</span>)
x[<span class="hljs-number">0</span>] = <span class="hljs-number">10</span> <span class="hljs-comment">//this will work</span>
</code></pre>
<p>In the above example, we declared x as []int however with <code>var</code>, we cannot provide the length of the slice. And hence the length of slice will remain zero. So in that case if you index the 0th index that will cause an error.</p>
<p>However, if you see the <code>make</code> example, we are passing 4 as the length. So x will be a slice with initial length of 4. So it will be safe to access the 0th index.</p>
<p>There is an additional way to decalare variables. Look at the below example</p>
<pre><code class="lang-go">x := <span class="hljs-built_in">new</span>(<span class="hljs-keyword">int</span>) <span class="hljs-comment">// intialized as 0</span>
fmt.Println(*x)
y := <span class="hljs-built_in">new</span>(<span class="hljs-keyword">string</span>) <span class="hljs-comment">// initialized as ""</span>
fmt.Println(*y)
z := <span class="hljs-built_in">new</span>([<span class="hljs-number">4</span>]<span class="hljs-keyword">int</span>) <span class="hljs-comment">// initialized as [0,0,0,0]</span>
fmt.Println(*z)
</code></pre>
<p>We can use the new keyword for allocating memory as per data type. However the variables will be pointer variables. We will discuss about pointers later.</p>
]]></content:encoded></item><item><title><![CDATA[Golang tricky output based interview questions]]></title><description><![CDATA[I've curated a list of output based questions for Golang interviews.
If you find any question difficult, Go Tour(https://go.dev/tour/welcome/1) is your best help. It will take atmost two days to cover all the slides.
After solving all, you will reali...]]></description><link>https://tech.latencot.com/golang-tricky-output-based-interview-questions</link><guid isPermaLink="true">https://tech.latencot.com/golang-tricky-output-based-interview-questions</guid><category><![CDATA[golang]]></category><category><![CDATA[interview questions]]></category><category><![CDATA[Go Language]]></category><category><![CDATA[output based]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Sat, 31 May 2025 10:11:41 GMT</pubDate><content:encoded><![CDATA[<p>I've curated a list of output based questions for Golang interviews.</p>
<p>If you find any question difficult, Go Tour(<a target="_blank" href="https://go.dev/tour/welcome/1">https://go.dev/tour/welcome/1</a>) is your best help. It will take atmost two days to cover all the slides.</p>
<p>After solving all, you will realize Golang has its own quirks, just like Javascript.</p>
<p>For answers, checkout: <a target="_blank" href="https://github.com/SankalpSTG/go-guide/blob/main/interview-questions/output-based/answers/README.md">https://github.com/SankalpSTG/go-guide/blob/main/interview-questions/output-based/answers/README.md</a></p>
<h3 id="heading-q1-what-will-be-the-output-for-the-following-code"><strong>Q1. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    funcs := []<span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">()</span></span>{}
    <span class="hljs-keyword">for</span> i := <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">3</span>; i++ {
        funcs = <span class="hljs-built_in">append</span>(funcs, <span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">()</span></span> { fmt.Println(i) })
    }
    <span class="hljs-keyword">for</span> _, f := <span class="hljs-keyword">range</span> funcs {
        f()
    }
}
</code></pre>
<h3 id="heading-q2-what-will-be-the-output-for-the-following-code"><strong>Q2. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    s := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
    t := s[:<span class="hljs-number">2</span>]
    t = <span class="hljs-built_in">append</span>(t, <span class="hljs-number">99</span>)
    fmt.Println(<span class="hljs-string">"s:"</span>, s)
    fmt.Println(<span class="hljs-string">"t:"</span>, t)
}
</code></pre>
<h3 id="heading-q3-what-will-be-the-output-for-the-following-code"><strong>Q3. What will be the output for the following code</strong></h3>
<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">f</span><span class="hljs-params">()</span> <span class="hljs-params">(x <span class="hljs-keyword">int</span>)</span></span> {
    <span class="hljs-keyword">defer</span> <span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">()</span></span> {
        x++
    }()
    <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    fmt.Println(f())
}
</code></pre>
<h3 id="heading-q4-what-will-be-the-output-for-the-following-code"><strong>Q4. What will be the output for the following code</strong></h3>
<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-keyword">type</span> T <span class="hljs-keyword">struct</span>{}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(t *T)</span> <span class="hljs-title">String</span><span class="hljs-params">()</span> <span class="hljs-title">string</span></span> {
    <span class="hljs-keyword">return</span> <span class="hljs-string">"I'm T"</span>
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> t *T = <span class="hljs-literal">nil</span>
    <span class="hljs-keyword">var</span> i fmt.Stringer = t
    fmt.Println(i == <span class="hljs-literal">nil</span>)
    fmt.Println(i)
}
</code></pre>
<h3 id="heading-q5-what-will-be-the-output-for-the-following-code"><strong>Q5. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    ch1 := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">chan</span> <span class="hljs-keyword">int</span>)
    ch2 := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">chan</span> <span class="hljs-keyword">int</span>)

    <span class="hljs-keyword">go</span> <span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">()</span></span> {
        ch1 &lt;- <span class="hljs-number">1</span>
    }()

    <span class="hljs-keyword">select</span> {
    <span class="hljs-keyword">case</span> x := &lt;-ch1:
        fmt.Println(<span class="hljs-string">"Received"</span>, x)
    <span class="hljs-keyword">case</span> y := &lt;-ch2:
        fmt.Println(<span class="hljs-string">"Received"</span>, y)
    }
}
</code></pre>
<h3 id="heading-q6-what-will-be-the-output-for-the-following-code"><strong>Q6. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    x := <span class="hljs-number">5</span>
    {
        x := x
        fmt.Println(x)
    }
}
</code></pre>
<h3 id="heading-q7-what-will-be-the-output-for-the-following-code"><strong>Q7. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">defer</span> fmt.Println(<span class="hljs-string">"deferred"</span>)
    <span class="hljs-built_in">panic</span>(<span class="hljs-string">"something went wrong"</span>)
    fmt.Println(<span class="hljs-string">"after panic"</span>)
}
</code></pre>
<h3 id="heading-q8-what-will-be-the-output-for-the-following-code"><strong>Q8. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    s := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
    t := s
    s = <span class="hljs-built_in">append</span>(s[:<span class="hljs-number">1</span>], s[<span class="hljs-number">2</span>:]...)
    fmt.Println(<span class="hljs-string">"s:"</span>, s)
    fmt.Println(<span class="hljs-string">"t:"</span>, t)
}
</code></pre>
<h3 id="heading-q9-what-will-be-the-output-for-the-following-code"><strong>Q9. What will be the output for the following code</strong></h3>
<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-keyword">type</span> MyStruct <span class="hljs-keyword">struct</span>{}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(m *MyStruct)</span> <span class="hljs-title">Error</span><span class="hljs-params">()</span> <span class="hljs-title">string</span></span> {
    <span class="hljs-keyword">return</span> <span class="hljs-string">"error from MyStruct"</span>
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> m *MyStruct = <span class="hljs-literal">nil</span>
    <span class="hljs-keyword">var</span> err error = m
    fmt.Println(err == <span class="hljs-literal">nil</span>)
    fmt.Println(err)
}
</code></pre>
<h3 id="heading-q10-what-will-be-the-output-for-the-following-code"><strong>Q10. What will be the output for the following code</strong></h3>
<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-string">"time"</span>
)

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    ch := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">chan</span> <span class="hljs-keyword">int</span>)

    <span class="hljs-keyword">select</span> {
    <span class="hljs-keyword">case</span> v := &lt;-ch:
        fmt.Println(<span class="hljs-string">"Received"</span>, v)
    <span class="hljs-keyword">default</span>:
        fmt.Println(<span class="hljs-string">"No value received"</span>)
    }

    time.Sleep(time.Second)
}
</code></pre>
<h3 id="heading-q11-what-will-be-the-output-for-the-following-code"><strong>Q11. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    m := <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">int</span>{
        <span class="hljs-string">"a"</span>: <span class="hljs-number">1</span>,
        <span class="hljs-string">"b"</span>: <span class="hljs-number">2</span>,
        <span class="hljs-string">"c"</span>: <span class="hljs-number">3</span>,
    }

    <span class="hljs-keyword">for</span> k, v := <span class="hljs-keyword">range</span> m {
        fmt.Println(k, v)
    }
}
</code></pre>
<h3 id="heading-q12-what-will-be-the-output-for-the-following-code"><strong>Q12. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    nums := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
    <span class="hljs-keyword">var</span> ptrs []*<span class="hljs-keyword">int</span>

    <span class="hljs-keyword">for</span> _, n := <span class="hljs-keyword">range</span> nums {
        ptrs = <span class="hljs-built_in">append</span>(ptrs, &amp;n)
    }

    <span class="hljs-keyword">for</span> _, p := <span class="hljs-keyword">range</span> ptrs {
        fmt.Println(*p)
    }
}
</code></pre>
<h3 id="heading-q13-what-will-be-the-output-for-the-following-code"><strong>Q13. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    s := <span class="hljs-string">"hello"</span>
    b := []<span class="hljs-keyword">byte</span>(s)
    b[<span class="hljs-number">0</span>] = <span class="hljs-string">'H'</span>
    fmt.Println(s)
    fmt.Println(<span class="hljs-keyword">string</span>(b))
}
</code></pre>
<h3 id="heading-q14-what-will-be-the-output-for-the-following-code"><strong>Q14. What will be the output for the following code</strong></h3>
<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-string">"time"</span>
)

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">for</span> i := <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">3</span>; i++ {
        <span class="hljs-keyword">go</span> <span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">()</span></span> {
            fmt.Println(i)
        }()
    }
    time.Sleep(time.Second)
}
</code></pre>
<h3 id="heading-q15-what-will-be-the-output-for-the-following-code"><strong>Q15. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> i <span class="hljs-keyword">interface</span>{} = <span class="hljs-number">10</span>
    s := i.(<span class="hljs-keyword">string</span>)
    fmt.Println(s)
}
</code></pre>
<h3 id="heading-q16-what-will-be-the-output-for-the-following-code"><strong>Q16. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    m := <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">int</span>{<span class="hljs-string">"a"</span>: <span class="hljs-number">1</span>, <span class="hljs-string">"b"</span>: <span class="hljs-number">2</span>}
    <span class="hljs-keyword">var</span> ptrs []*<span class="hljs-keyword">int</span>

    <span class="hljs-keyword">for</span> _, v := <span class="hljs-keyword">range</span> m {
        ptrs = <span class="hljs-built_in">append</span>(ptrs, &amp;v)
    }

    <span class="hljs-keyword">for</span> _, p := <span class="hljs-keyword">range</span> ptrs {
        fmt.Println(*p)
    }
}
</code></pre>
<h3 id="heading-q17-what-will-be-the-output-for-the-following-code"><strong>Q17. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    a := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>}
    b := a[:<span class="hljs-number">2</span>]
    c := a[<span class="hljs-number">2</span>:]
    b = <span class="hljs-built_in">append</span>(b, <span class="hljs-number">99</span>)
    fmt.Println(<span class="hljs-string">"a:"</span>, a)
    fmt.Println(<span class="hljs-string">"b:"</span>, b)
    fmt.Println(<span class="hljs-string">"c:"</span>, c)
}
</code></pre>
<h3 id="heading-q18-what-will-be-the-output-for-the-following-code"><strong>Q18. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">defer</span> <span class="hljs-function"><span class="hljs-keyword">func</span><span class="hljs-params">()</span></span> {
        <span class="hljs-keyword">if</span> r := <span class="hljs-built_in">recover</span>(); r != <span class="hljs-literal">nil</span> {
            fmt.Println(<span class="hljs-string">"Recovered:"</span>, r)
        } <span class="hljs-keyword">else</span> {
            fmt.Println(<span class="hljs-string">"No panic occurred"</span>)
        }
    }()
    fmt.Println(<span class="hljs-string">"Doing fine"</span>)
}
</code></pre>
<h3 id="heading-q19-what-will-be-the-output-for-the-following-code"><strong>Q19. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">const</span> x = <span class="hljs-number">10</span>
    {
        <span class="hljs-keyword">var</span> x = <span class="hljs-number">20</span>
        fmt.Println(x)
    }
    fmt.Println(x)
}
</code></pre>
<h3 id="heading-q20-what-will-be-the-output-for-the-following-code"><strong>Q20. What will be the output for the following code</strong></h3>
<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-keyword">type</span> Person <span class="hljs-keyword">struct</span> {
    name <span class="hljs-keyword">string</span>
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    p1 := Person{name: <span class="hljs-string">"Alice"</span>}
    p2 := p1
    p2.name = <span class="hljs-string">"Bob"</span>

    fmt.Println(p1.name)
    fmt.Println(p2.name)
}
</code></pre>
<h3 id="heading-q21-what-will-be-the-output-for-the-following-code"><strong>Q21. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> a []<span class="hljs-keyword">int</span>
    b := []<span class="hljs-keyword">int</span>{}

    fmt.Println(a == <span class="hljs-literal">nil</span>)
    fmt.Println(b == <span class="hljs-literal">nil</span>)
}
</code></pre>
<h3 id="heading-q22-what-will-be-the-output-for-the-following-code"><strong>Q22. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">for</span> i := <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">3</span>; fmt.Println(i) {
        i++
    }
}
</code></pre>
<h3 id="heading-q23-what-will-be-the-output-for-the-following-code"><strong>Q23. What will be the output for the following code</strong></h3>
<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">modifyArr</span><span class="hljs-params">(a [3]<span class="hljs-keyword">int</span>)</span></span> {
    a[<span class="hljs-number">0</span>] = <span class="hljs-number">100</span>
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">modifySlice</span><span class="hljs-params">(s []<span class="hljs-keyword">int</span>)</span></span> {
    s[<span class="hljs-number">0</span>] = <span class="hljs-number">100</span>
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    arr := [<span class="hljs-number">3</span>]<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
    slice := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}

    modifyArr(arr)
    modifySlice(slice)

    fmt.Println(arr)
    fmt.Println(slice)
}
</code></pre>
<h3 id="heading-q24-what-will-be-the-output-for-the-following-code"><strong>Q24. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    res := <span class="hljs-built_in">make</span>([][]<span class="hljs-keyword">int</span>, <span class="hljs-number">0</span>)
    row := []<span class="hljs-keyword">int</span>{}

    <span class="hljs-keyword">for</span> i := <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">3</span>; i++ {
        row = <span class="hljs-built_in">append</span>(row, i)
        res = <span class="hljs-built_in">append</span>(res, row)
    }

    fmt.Println(res)
}
</code></pre>
<h3 id="heading-q25-what-will-be-the-output-for-the-following-code"><strong>Q25. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    x := <span class="hljs-number">2</span>
    <span class="hljs-keyword">switch</span> x {
    <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>:
        fmt.Println(<span class="hljs-string">"One"</span>)
        <span class="hljs-keyword">fallthrough</span>
    <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>:
        fmt.Println(<span class="hljs-string">"Two"</span>)
        <span class="hljs-keyword">fallthrough</span>
    <span class="hljs-keyword">case</span> <span class="hljs-number">3</span>:
        fmt.Println(<span class="hljs-string">"Three"</span>)
    <span class="hljs-keyword">default</span>:
        fmt.Println(<span class="hljs-string">"Default"</span>)
    }
}
</code></pre>
<h3 id="heading-q26-what-will-be-the-output-for-the-following-code"><strong>Q26. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> nums []<span class="hljs-keyword">int</span>

    <span class="hljs-keyword">for</span> _, v := <span class="hljs-keyword">range</span> nums {
        fmt.Println(v)
    }

    fmt.Println(<span class="hljs-string">"done"</span>)
}
</code></pre>
<h3 id="heading-q27-what-will-be-the-output-for-the-following-code"><strong>Q27. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    ch := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">chan</span> <span class="hljs-keyword">int</span>)
    ch &lt;- <span class="hljs-number">10</span>
    fmt.Println(<span class="hljs-string">"done"</span>)
}
</code></pre>
<h3 id="heading-q28-what-will-be-the-output-for-the-following-code"><strong>Q28. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    s := <span class="hljs-built_in">make</span>([]<span class="hljs-keyword">int</span>, <span class="hljs-number">0</span>, <span class="hljs-number">2</span>)
    capBefore := <span class="hljs-built_in">cap</span>(s)

    s = <span class="hljs-built_in">append</span>(s, <span class="hljs-number">1</span>)
    s = <span class="hljs-built_in">append</span>(s, <span class="hljs-number">2</span>)
    capAfter := <span class="hljs-built_in">cap</span>(s)

    s = <span class="hljs-built_in">append</span>(s, <span class="hljs-number">3</span>)
    capFinal := <span class="hljs-built_in">cap</span>(s)

    fmt.Println(capBefore, capAfter, capFinal)
}
</code></pre>
<h3 id="heading-q29-what-will-be-the-output-for-the-following-code"><strong>Q29. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> i <span class="hljs-keyword">interface</span>{} = <span class="hljs-literal">nil</span>
    fmt.Println(i == <span class="hljs-literal">nil</span>)

    <span class="hljs-keyword">var</span> p *<span class="hljs-keyword">int</span> = <span class="hljs-literal">nil</span>
    i = p
    fmt.Println(i == <span class="hljs-literal">nil</span>)
}
</code></pre>
<h3 id="heading-q30-what-will-be-the-output-for-the-following-code"><strong>Q30. What will be the output for the following code</strong></h3>
<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-keyword">type</span> A <span class="hljs-keyword">struct</span>{}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(a A)</span> <span class="hljs-title">Foo</span><span class="hljs-params">()</span></span> {
    fmt.Println(<span class="hljs-string">"A Foo"</span>)
}

<span class="hljs-keyword">type</span> B <span class="hljs-keyword">struct</span> {
    A
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    b := B{}
    b.Foo()
}
</code></pre>
<h3 id="heading-q31-what-will-be-the-output-for-the-following-code"><strong>Q31. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> s1 []<span class="hljs-keyword">int</span>
    s2 := []<span class="hljs-keyword">int</span>{}

    fmt.Println(<span class="hljs-built_in">len</span>(s1), <span class="hljs-built_in">cap</span>(s1), s1 == <span class="hljs-literal">nil</span>)
    fmt.Println(<span class="hljs-built_in">len</span>(s2), <span class="hljs-built_in">cap</span>(s2), s2 == <span class="hljs-literal">nil</span>)
}
</code></pre>
<h3 id="heading-q32-what-will-be-the-output-for-the-following-code"><strong>Q32. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    x := <span class="hljs-number">5</span>
    <span class="hljs-keyword">defer</span> fmt.Println(x)
    x = <span class="hljs-number">10</span>
}
</code></pre>
<h3 id="heading-q33-what-will-be-the-output-for-the-following-code"><strong>Q33. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> m1 <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">int</span>
    m2 := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">int</span>)

    fmt.Println(m1 == <span class="hljs-literal">nil</span>)
    fmt.Println(m2 == <span class="hljs-literal">nil</span>)

    m2[<span class="hljs-string">"key"</span>] = <span class="hljs-number">1</span>
    <span class="hljs-comment">// m1["key"] = 1  // Uncommenting this will cause what?</span>
}
</code></pre>
<h3 id="heading-q34-what-will-be-the-output-for-the-following-code"><strong>Q34. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    s := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>}
    s1 := s[:<span class="hljs-number">3</span>]
    s2 := s[<span class="hljs-number">3</span>:]

    s1 = <span class="hljs-built_in">append</span>(s1, <span class="hljs-number">10</span>)
    s2[<span class="hljs-number">0</span>] = <span class="hljs-number">20</span>

    fmt.Println(s)
    fmt.Println(s1)
    fmt.Println(s2)
}
</code></pre>
<h3 id="heading-q35-what-will-be-the-output-for-the-following-code"><strong>Q35. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> i <span class="hljs-keyword">interface</span>{} = (*<span class="hljs-keyword">int</span>)(<span class="hljs-literal">nil</span>)

    v, ok := i.(*<span class="hljs-keyword">int</span>)
    fmt.Println(v, ok)
}
</code></pre>
<h3 id="heading-q36-what-will-be-the-output-for-the-following-code"><strong>Q36. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    m := <span class="hljs-keyword">map</span>[<span class="hljs-keyword">int</span>]<span class="hljs-keyword">string</span>{
        <span class="hljs-number">1</span>: <span class="hljs-string">"one"</span>,
        <span class="hljs-number">2</span>: <span class="hljs-string">"two"</span>,
        <span class="hljs-number">3</span>: <span class="hljs-string">"three"</span>,
    }

    <span class="hljs-keyword">for</span> k := <span class="hljs-keyword">range</span> m {
        fmt.Print(k, <span class="hljs-string">" "</span>)
    }
}
</code></pre>
<h3 id="heading-q37-what-will-be-the-output-for-the-following-code"><strong>Q37. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    ch := <span class="hljs-built_in">make</span>(<span class="hljs-keyword">chan</span> <span class="hljs-keyword">int</span>, <span class="hljs-number">3</span>)
    ch &lt;- <span class="hljs-number">1</span>
    ch &lt;- <span class="hljs-number">2</span>
    ch &lt;- <span class="hljs-number">3</span>
    <span class="hljs-built_in">close</span>(ch)

    <span class="hljs-keyword">for</span> v := <span class="hljs-keyword">range</span> ch {
        fmt.Print(v, <span class="hljs-string">" "</span>)
    }
}
</code></pre>
<h3 id="heading-q38-what-will-be-the-output-for-the-following-code"><strong>Q38. What will be the output for the following code</strong></h3>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> (
    <span class="hljs-string">"encoding/json"</span>
    <span class="hljs-string">"fmt"</span>
)

<span class="hljs-keyword">type</span> Base <span class="hljs-keyword">struct</span> {
    ID <span class="hljs-keyword">int</span> <span class="hljs-string">`json:"id"`</span>
}

<span class="hljs-keyword">type</span> User <span class="hljs-keyword">struct</span> {
    Base
    Name <span class="hljs-keyword">string</span> <span class="hljs-string">`json:"name"`</span>
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    data := []<span class="hljs-keyword">byte</span>(<span class="hljs-string">`{"id":10, "name":"Alice"}`</span>)
    <span class="hljs-keyword">var</span> u User
    json.Unmarshal(data, &amp;u)
    fmt.Println(u.ID, u.Name)
}
</code></pre>
<h3 id="heading-q39-what-will-be-the-output-for-the-following-code"><strong>Q39. What will be the output for the following code</strong></h3>
<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-keyword">const</span> (
    a = <span class="hljs-literal">iota</span>
    b
    c = <span class="hljs-number">5</span>
    d
    e = <span class="hljs-literal">iota</span>
)

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
    fmt.Println(a, b, c, d, e)
}
</code></pre>
<h3 id="heading-q40-what-will-be-the-output-for-the-following-code"><strong>Q40. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    <span class="hljs-keyword">var</span> err error
    fmt.Println(err == <span class="hljs-literal">nil</span>)

    err = (*<span class="hljs-keyword">struct</span>{})(<span class="hljs-literal">nil</span>)
    fmt.Println(err == <span class="hljs-literal">nil</span>)
}
</code></pre>
<h3 id="heading-q41-what-will-be-the-output-for-the-following-code"><strong>Q41. What will be the output for the following code</strong></h3>
<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">main</span><span class="hljs-params">()</span></span> {
    s := []<span class="hljs-keyword">int</span>{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>}
    s1 := s[:<span class="hljs-number">3</span>]
    s2 := s1[:<span class="hljs-number">4</span>]

    fmt.Println(s2)
}
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Command Query Responsibility Segregation (CQRS)]]></title><description><![CDATA[Command Query Responsibility Segregation (CQRS) in simple terms is a design pattern in which you separate write commands (Create, Update, Delete) and read queries (Get) into different models.
What is the advantage of implementing CQRS?
CQRS help scal...]]></description><link>https://tech.latencot.com/command-query-responsibility-segregation-cqrs</link><guid isPermaLink="true">https://tech.latencot.com/command-query-responsibility-segregation-cqrs</guid><category><![CDATA[System Design]]></category><category><![CDATA[design patterns]]></category><category><![CDATA[General Programming]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Wed, 28 May 2025 04:50:04 GMT</pubDate><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748407704688/f11851df-94f7-44a2-a9da-28dbf06e6e58.png" alt class="image--center mx-auto" /></p>
<p>Command Query Responsibility Segregation (CQRS) in simple terms is a design pattern in which you separate write commands (Create, Update, Delete) and read queries (Get) into different models.</p>
<p>What is the advantage of implementing CQRS?</p>
<p>CQRS help scale read and write operations independently.</p>
<p>CQRS allows read queries to be denormalized, that means read will be faster, while commands can adhere business logic strictly. In short, CQRS can help you with building read heavy systems.</p>
<p>Nest.js supports implementation of CQRS, you can read here: <a target="_blank" href="https://docs.nestjs.com/recipes/cqrs">https://docs.nestjs.com/recipes/cqrs</a></p>
<p>Nest.js will only help you with implementing CQRS on a structural level. In real world implementation for large scale, you will be creating different microservices for read and write. Everytime writes happen, the read service has to be notified about changes in the data.</p>
<p>CQRS adds complexity and might feel unnecessary in situations. There are better patterns with Caching that you can implement over or with CQRS and that will be totally fine.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748407727450/9f993821-8824-45fe-a4de-86a64f7e3cd6.png" alt class="image--center mx-auto" /></p>
<p>CQRS is something that you can do with monoliths and later break it apart into different microservices. And hence it perfectly makes sense.</p>
<p>Read this if you want to know more about CQRS and it's implementation in Go: <a target="_blank" href="https://threedots.tech/post/basic-cqrs-in-go/">https://threedots.tech/post/basic-cqrs-in-go/</a></p>
]]></content:encoded></item><item><title><![CDATA[What are presigned urls?]]></title><description><![CDATA[Presigned urls as the name suggest are presigned. They have their signature / token with them.
When you want to upload a file to some object storage service like AWS S3 or GCS, there are two ways you can upload files

Through backend, using AWS / GCP...]]></description><link>https://tech.latencot.com/what-are-presigned-urls</link><guid isPermaLink="true">https://tech.latencot.com/what-are-presigned-urls</guid><category><![CDATA[AWS]]></category><category><![CDATA[S3]]></category><category><![CDATA[#gcs]]></category><category><![CDATA[google cloud]]></category><category><![CDATA[s3 presigned URL]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Sat, 24 May 2025 05:22:42 GMT</pubDate><content:encoded><![CDATA[<p>Presigned urls as the name suggest are presigned. They have their signature / token with them.</p>
<p>When you want to upload a file to some object storage service like AWS S3 or GCS, there are two ways you can upload files</p>
<ol>
<li><p>Through backend, using AWS / GCP standard libraries.</p>
</li>
<li><p>Through presigned urls</p>
</li>
</ol>
<p>Why would you do presigned urls?</p>
<p>Servers often have limits on how much data can you upload at a time. Google Cloud run has a limit of 32MB, but if you use Compute Engine, it has no limits. Similarly AWS EC2 and ECS does not have limits but AWS Lambda has a limit of 10MB. So mostly serverless platforms have a limit not defined by you.</p>
<p>But in any case, uploading through backend won't be a good choice because you are unnecessarily eating up the bandwidth while uploading the file. This works for 10-20 files but if you have 1000 files of 100MB each, you can imagine what would happen.</p>
<p>How do we use presigned urls?</p>
<p>We request our server, that we want to upload a file, we provide the type of file and where we want to upload this file. The server should then request AWS S3 / GCS (or whatever service you are using) to create a presigned url. We can set the validity of this url.</p>
<p>Then we send this URL to the client. The client can then securely send the file on this URL.</p>
<p>There are practical limits for file size for presigned urls (5GB per file) but a good practice is, let's say if you have a file of 1GB, you break it into chunks of 10MB. You will have 100 chunks. Now you request for a presigned url for each chunk and then upload that chunk.</p>
<p>Once uploaded, you can combine all chunks on the S3 to make the file again. This is a common practice and this enables you to pause and resume your uploads as well.</p>
<p>AWS S3 allows 10,000 chunks per file and each chunk should be of size more than 5MB. These are some restrictions that AWS applies. This way, you can upload files of up to 5TB on AWS.</p>
<pre><code class="lang-go"><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(m *S3Service)</span> <span class="hljs-title">getPresignedUrl</span><span class="hljs-params">(bucket constant.Bucket, key <span class="hljs-keyword">string</span>)</span> <span class="hljs-params">(<span class="hljs-keyword">string</span>, error)</span></span> {
    presignClient := s3.NewPresignClient(m.s3Client)
    url, err := presignClient.PresignPutObject(context.TODO(), &amp;s3.PutObjectInput{
        Bucket: aws.String(<span class="hljs-keyword">string</span>(bucket)),
        Key:    aws.String(key),
    }, s3.WithPresignExpires(<span class="hljs-number">15</span>*time.Minute))
    <span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-string">""</span>, err
    }
    <span class="hljs-keyword">return</span> url.URL, <span class="hljs-literal">nil</span>
}
</code></pre>
<p>The above is a go snippet to generate a presigned url. A presigned url might look like below</p>
<pre><code class="lang-markdown">https://some-bucket.s3.region.amazonaws.com/some-prefix/some-key?X-Amz-Algorithm=AWS4-HMAC-SHA256
&amp;X-Amz-Credential=some-credentials&amp;X-Amz-Date=20250523T101848Z&amp;X-Amz-Expires=900
&amp;X-Amz-SignedHeaders=host&amp;x-id=PutObject&amp;X-Amz-Signature=some-signature
</code></pre>
<p>There are some headers like</p>
<ol>
<li><p>X-Amz-Algorithm</p>
</li>
<li><p>X-Amz-Credential</p>
</li>
<li><p>X-Amz-Date</p>
</li>
<li><p>X-Amz-Expires</p>
</li>
<li><p>X-Amz-SignedHeaders</p>
</li>
<li><p>x-id</p>
</li>
<li><p>X-Amz-Signature</p>
</li>
</ol>
<p>Now, using this, anyone can make a <code>PUT</code> request and upload a file to S3.</p>
<p>For multipart uploads, we will talk this in some other post.</p>
<p>Thanks.</p>
]]></content:encoded></item><item><title><![CDATA[The "Idiomatic" Golang]]></title><description><![CDATA[When working with Golang, you will read one word; "idiomatic" alot on all the forums and in the community discussions.
But what does idiomatic actually mean?
Idiomatic, this word is only and only associated to Golang. Generally idiomatic in programmi...]]></description><link>https://tech.latencot.com/the-idiomatic-golang</link><guid isPermaLink="true">https://tech.latencot.com/the-idiomatic-golang</guid><category><![CDATA[idiomatic]]></category><category><![CDATA[dogmatic]]></category><category><![CDATA[Go Language]]></category><category><![CDATA[golang]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Sun, 18 May 2025 15:48:34 GMT</pubDate><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1747583137443/6d2a59a4-44f7-4294-a1ea-b39c9b845b79.png" alt class="image--center mx-auto" /></p>
<p>When working with Golang, you will read one word; "idiomatic" alot on all the forums and in the community discussions.</p>
<p>But what does idiomatic actually mean?</p>
<p>Idiomatic, this word is only and only associated to Golang. Generally idiomatic in programming means writing code that follows the conventions, style, and best practices of the language you're using.</p>
<p>We use idiomatic a lot while talking about Go, because Golang's way of doing things is a bit different as compared to other general purpose languages. And hence many a times when you try to do something in Golang, the way you did the same in an OOPP environment like Java and C++, you might break patterns or you might not follow the idiomatic way of doing things in Go.</p>
<p>In Go, idiomatic code usually means:</p>
<ol>
<li><p>Keeping things simple and readable</p>
</li>
<li><p>Using structs and interfaces effectively</p>
</li>
<li><p>Avoiding unnecessary abstraction</p>
</li>
<li><p>Keeping functions small and doing one thing</p>
</li>
<li><p>Reusing instead of re-initializing</p>
</li>
</ol>
<p>The problem is, this is so vague, the Go community does suffer problem where someone might say something is idiomatic while the others saying it is not.</p>
<p>But Golang is evolving just like any other language and new features (for e.g. generics) are allowing you to decide what you can do and what you "should not" do. It is not "can not" and it is always "should not" while the community forces "must not".</p>
<p>At the end, if your Go code doesn't look simple, if your code does magic at runtime (hidden dependency injection), if your code enforces a lot of rules, maybe you are over engineering. Go likes to be simple (while it's verbosity doesn't look simple) and Go asks you to write small functions, simple &amp; efficient code.</p>
]]></content:encoded></item><item><title><![CDATA[Primitive Data Types in Go]]></title><description><![CDATA[Unlike languages like Python and Javascript, Go is statically typed. That means once a variable type is defined, the variable will only store that type of data.
Go has 3 basic types

bool

Numeric

string


Bool
To declare a variable and then initali...]]></description><link>https://tech.latencot.com/primitive-data-types-in-go</link><guid isPermaLink="true">https://tech.latencot.com/primitive-data-types-in-go</guid><category><![CDATA[Go Language]]></category><category><![CDATA[golang]]></category><category><![CDATA[datatypes]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Sun, 18 May 2025 05:20:40 GMT</pubDate><content:encoded><![CDATA[<p>Unlike languages like Python and Javascript, Go is statically typed. That means once a variable type is defined, the variable will only store that type of data.</p>
<p>Go has 3 basic types</p>
<ol>
<li><p>bool</p>
</li>
<li><p>Numeric</p>
</li>
<li><p>string</p>
</li>
</ol>
<h3 id="heading-bool"><strong>Bool</strong></h3>
<p>To declare a variable and then initalize it, you can do it following way:</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> myVar <span class="hljs-keyword">bool</span>                     <span class="hljs-comment">//type declaration</span>
myVar = <span class="hljs-literal">false</span>                     <span class="hljs-comment">//value initialization</span>
<span class="hljs-keyword">var</span> myVar2 <span class="hljs-keyword">bool</span> = <span class="hljs-literal">false</span> <span class="hljs-comment">//type declaration and initialization</span>
</code></pre>
<p>There is a special short cut operator to declare and define variables in Go:</p>
<pre><code class="lang-go">myVar := <span class="hljs-literal">false</span>
</code></pre>
<p>In the above code, using the <code>:=</code> operator, we can directly declare and assign the variable a value. The type is automatically inferred from the value.</p>
<h3 id="heading-integers"><strong>Integers</strong></h3>
<p>There are two types of integers</p>
<ol>
<li><p>Signed integers</p>
</li>
<li><p>Unsigned integers</p>
</li>
</ol>
<p>Signed integers are declared with the int prefixed keywords</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> x <span class="hljs-keyword">int</span> = <span class="hljs-number">200</span>
<span class="hljs-keyword">var</span> y <span class="hljs-keyword">int8</span> = <span class="hljs-number">-100</span>
</code></pre>
<p>There are five types of int:</p>
<ol>
<li><p>int -&gt; 32 bits for 32 bit systems and 64 bits for 64 bit systems.</p>
</li>
<li><p>int8 -&gt; 8 bit integer storing from -128 to 127</p>
</li>
<li><p>int16 -&gt; 16 bit integer storing from -32768 to 32767</p>
</li>
<li><p>int32 -&gt; 32 bit integer storing from +/- 2^31</p>
</li>
<li><p>int64 -&gt; 64 bit integer storing from +/- 2^63</p>
</li>
</ol>
<p>You can use these keywords to define integers.</p>
<p>Unsigned integers can be defined using uint prefixed key</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> x <span class="hljs-keyword">uint</span> = <span class="hljs-number">1200</span>
<span class="hljs-keyword">var</span> x <span class="hljs-keyword">uint16</span> = <span class="hljs-number">2456</span>
</code></pre>
<p>Similar to int, you have five types of uint</p>
<ol>
<li><p>int -&gt; 32 bits for 32 bit systems and 64 bits for 64 bit systems.</p>
</li>
<li><p>int8 -&gt; 8 bit storing positive values from 0 to 2^8</p>
</li>
<li><p>int16 -&gt; 16 bit storing positive values from 0 to 2^16</p>
</li>
<li><p>int32 -&gt; 32 bit storing positive values from 0 to 2^32</p>
</li>
<li><p>int64 -&gt; 64 bit storing positive values from 0 to 2^64</p>
</li>
</ol>
<p>There are two aliases for uint8 and int32</p>
<ol>
<li><p>btye -&gt; alias for uint8</p>
</li>
<li><p>rune -&gt; alias for int32</p>
</li>
</ol>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> m <span class="hljs-keyword">rune</span> = <span class="hljs-number">-42</span>
<span class="hljs-keyword">var</span> n <span class="hljs-keyword">byte</span> = <span class="hljs-number">37</span>
fmt.Println(reflect.TypeOf(m), reflect.TypeOf(n))
</code></pre>
<p><code>m</code> will be <code>int32</code> whereas n will be <code>uint8</code></p>
<h3 id="heading-float"><strong>Float</strong></h3>
<p>There are two types of floats</p>
<ol>
<li><p>float32 -&gt; 32 bit float storing from -3.4e+38 to 3.4e+38</p>
</li>
<li><p>float64 -&gt; 64 bit float storing from -1.7e+308 to 1.7e+308</p>
</li>
</ol>
<p>The default type is float64 in case you use <code>:=</code> for defining a variable.</p>
<pre><code class="lang-go">x := <span class="hljs-number">3.44</span>                <span class="hljs-comment">//float64</span>
<span class="hljs-keyword">var</span> y <span class="hljs-keyword">float32</span> = <span class="hljs-number">3e+38</span>
<span class="hljs-keyword">var</span> y <span class="hljs-keyword">float64</span> = <span class="hljs-number">17.323</span>
</code></pre>
<h3 id="heading-string"><strong>String</strong></h3>
<p>Strings can be defined using the <code>string</code> keyword</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> x <span class="hljs-keyword">string</span> = <span class="hljs-string">"Hello, World!"</span>
y := <span class="hljs-string">"My name is awesome!"</span>
</code></pre>
<h3 id="heading-complex"><strong>Complex</strong></h3>
<p>Go also supports complex numbers as follows</p>
<pre><code class="lang-go">a := <span class="hljs-built_in">complex</span>(<span class="hljs-number">1.2</span>, <span class="hljs-number">3.4</span>)
<span class="hljs-keyword">var</span> b <span class="hljs-keyword">complex128</span> := <span class="hljs-built_in">complex</span>(<span class="hljs-number">1.2</span>, <span class="hljs-number">3.4</span>)
c := <span class="hljs-number">8</span> + <span class="hljs-number">7i</span>
</code></pre>
<p>Complex numbers is the same mathematical concept where you had a real and an imaginary number. Both the real and imaginary part are floats either float32 or float64.</p>
<p>Complex numbers can be either 128bit or 64bit</p>
<ol>
<li><p>complex128 -&gt; 64bit f real + 64bit imaginary</p>
</li>
<li><p>complex64 -&gt; 32bit real + 32bit imaginary</p>
</li>
</ol>
<h3 id="heading-zero-values"><strong>Zero Values</strong></h3>
<p>Following are the zero values, which are given when variables are declared without initializing</p>
<ol>
<li><p><code>0</code> for numeric types</p>
</li>
<li><p><code>false</code> for boolean type</p>
</li>
<li><p><code>""</code> for strings</p>
</li>
</ol>
<h3 id="heading-null"><strong>Null</strong></h3>
<p>In Golang, <code>null</code> is replaced with <code>nil</code>. We will talk more about <code>nil</code> when discussing pointers and interfaces.</p>
]]></content:encoded></item><item><title><![CDATA[𝐎𝐩𝐭𝐢𝐦𝐢𝐬𝐭𝐢𝐜 𝐯𝐬 𝐏𝐞𝐬𝐬𝐢𝐦𝐢𝐬𝐭𝐢𝐜 𝐋𝐨𝐜𝐤𝐢𝐧𝐠, 𝐢𝐧 𝐃𝐚𝐭𝐚𝐛𝐚𝐬𝐞𝐬]]></title><description><![CDATA[When building applications that deal with concurrent access to shared data, data consistency becomes a real challenge. Two popular approaches to handle this are Optimistic Locking and Pessimistic Locking. But they serve different purposes and come wi...]]></description><link>https://tech.latencot.com/8j2qjvcdkknwnzct8j2qovcdkkbwnzci8j2qrpcdkk3wnzci8j2qncdwnzcv8j2qrcdwnzcp8j2qnvcdkkzwnzcs8j2qovcdkkbwnzci8j2qrpcdkk3wnzci8j2qncdwnzcl8j2qqpcdkjzwnzck8j2qovcdkkfwnzcglcdwnzci8j2qpydwnzcd8j2qmvcdkk3wnzca8j2qmcdkjrwnzcs8j2qnvcdkkw</link><guid isPermaLink="true">https://tech.latencot.com/8j2qjvcdkknwnzct8j2qovcdkkbwnzci8j2qrpcdkk3wnzci8j2qncdwnzcv8j2qrcdwnzcp8j2qnvcdkkzwnzcs8j2qovcdkkbwnzci8j2qrpcdkk3wnzci8j2qncdwnzcl8j2qqpcdkjzwnzck8j2qovcdkkfwnzcglcdwnzci8j2qpydwnzcd8j2qmvcdkk3wnzca8j2qmcdkjrwnzcs8j2qnvcdkkw</guid><category><![CDATA[SQL]]></category><category><![CDATA[MongoDB]]></category><category><![CDATA[concurrency]]></category><category><![CDATA[transactions]]></category><category><![CDATA[ACID Transactions]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Sat, 17 May 2025 04:14:01 GMT</pubDate><content:encoded><![CDATA[<p>When building applications that deal with concurrent access to shared data, data consistency becomes a real challenge. Two popular approaches to handle this are Optimistic Locking and Pessimistic Locking. But they serve different purposes and come with trade-offs.  </p>
<p>𝐎𝐩𝐭𝐢𝐦𝐢𝐬𝐭𝐢𝐜 𝐋𝐨𝐜𝐤𝐢𝐧𝐠:  </p>
<p>𝐀𝐬𝐬𝐮𝐦𝐩𝐭𝐢𝐨𝐧: Conflicts are rare.  </p>
<p>𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Let everyone access the data, but verify before committing changes.  </p>
<p>𝐇𝐨𝐰 𝐢𝐭 𝐰𝐨𝐫𝐤𝐬:  </p>
<p>- A version field (e.g., version or updatedAt) is stored with the record.  </p>
<p>- Before updating, the application checks whether the version matches.  </p>
<p>- If not, the operation fails and must be retried.  </p>
<p>For e.g. in SQL:</p>
<pre><code class="lang-typescript">UPDATE orders SET status = <span class="hljs-string">'shipped'</span>, version = version + <span class="hljs-number">1</span> WHERE id = <span class="hljs-number">101</span> AND version = <span class="hljs-number">2</span>;
</code></pre>
<p>Mongodb Example:</p>
<pre><code class="lang-typescript">db.items.updateOne(
 { id: itemId, version: <span class="hljs-number">3</span> },
 { $set: { name: <span class="hljs-string">"New Name"</span> }, $inc: { version: <span class="hljs-number">1</span> } }
)
</code></pre>
<p>If version has changed, the update fails indicating someone else modified it.  </p>
<p>𝐓𝐡𝐢𝐬 𝐢𝐬 𝐔𝐬𝐞𝐝 𝐢𝐧:  </p>
<p>- High-read, low-write systems  </p>
<p>- APIs with stateless communication  </p>
<p>- Systems needing scalability over strict locking  </p>
<p>𝐏𝐞𝐬𝐬𝐢𝐦𝐢𝐬𝐭𝐢𝐜 𝐋𝐨𝐜𝐤𝐢𝐧𝐠  </p>
<p>𝐀𝐬𝐬𝐮𝐦𝐩𝐭𝐢𝐨𝐧: Conflicts are likely.  </p>
<p>𝐇𝐨𝐰 𝐢𝐭 𝐰𝐨𝐫𝐤𝐬:  </p>
<p>- Lock the data to prevent others from modifying it until the lock is released.  </p>
<p>- Other operations must wait or fail.  </p>
<p>For e.g. in SQL</p>
<pre><code class="lang-typescript">SELECT * FROM orders WHERE id = <span class="hljs-number">101</span> FOR UPDATE;
</code></pre>
<p>MongoDB does not natively supports Pessimistic Locking but this can still be implemented with adding an additional lock field:</p>
<pre><code class="lang-typescript">db.items.updateOne(
 { id: itemId, locked: <span class="hljs-literal">false</span> },
 { $set: { locked: <span class="hljs-literal">true</span> } }
)
</code></pre>
<p>Pessimistic Locks are needed in high concurrency systems such as BookMyShow or District where multiple people might attempt to book the same seat or spot.</p>
]]></content:encoded></item><item><title><![CDATA[Variables in Go]]></title><description><![CDATA[Variables in go can be declared using following syntax
var <variable-name> <data-type> = <value>

For e.g.
package main

func main(){
    var x int = 40
}

There is also a shortcut of defining variables
package main

func main(){
    x := 10
}

In th...]]></description><link>https://tech.latencot.com/variables-in-go</link><guid isPermaLink="true">https://tech.latencot.com/variables-in-go</guid><category><![CDATA[Go Language]]></category><category><![CDATA[variables]]></category><category><![CDATA[constants in go]]></category><category><![CDATA[golang]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Sat, 17 May 2025 01:21:45 GMT</pubDate><content:encoded><![CDATA[<p>Variables in go can be declared using following syntax</p>
<pre><code class="lang-plaintext">var &lt;variable-name&gt; &lt;data-type&gt; = &lt;value&gt;
</code></pre>
<p>For e.g.</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span>{
    <span class="hljs-keyword">var</span> x <span class="hljs-keyword">int</span> = <span class="hljs-number">40</span>
}
</code></pre>
<p>There is also a shortcut of defining variables</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span>{
    x := <span class="hljs-number">10</span>
}
</code></pre>
<p>In the above case, we have used the <code>:=</code> operator which is the shortcut method to declare variables. You don’t need to write <code>var</code> neither do you need to write the <code>type</code>. The type is inferred from the value. Basically whatever value is, the type is assigned accordingly.</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> (
    <span class="hljs-string">"reflect"</span>
    <span class="hljs-string">"fmt"</span>
)

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span>{
    x := <span class="hljs-number">10</span>
    y := <span class="hljs-string">"I am a string"</span>
    fmt.Println(reflect.TypeOf(x), reflect.TypeOf(y))
}
</code></pre>
<p>In the above example, we have imported the reflect package which is a standard built-in package for go. Using reflect, we can determine the type of x and y. You will notice x will be int and y will be string.</p>
<h2 id="heading-defining-variables-in-bulk">Defining Variables in Bulk</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">main</span><span class="hljs-params">()</span></span>{
    <span class="hljs-keyword">var</span> (    
        c = <span class="hljs-number">10</span>
        d = <span class="hljs-number">20</span>
        e = <span class="hljs-number">30</span>
    )
    fmt.Println(c, d, e)
    <span class="hljs-keyword">var</span> (
        f <span class="hljs-keyword">int</span>
        g <span class="hljs-keyword">int</span>
        h <span class="hljs-keyword">int</span>
    )
    fmt.Println(f, g, h)
    <span class="hljs-keyword">var</span> i, j, k <span class="hljs-keyword">int</span>
    i = <span class="hljs-number">1</span>
    j = <span class="hljs-number">2</span>
    k = <span class="hljs-number">3</span>
    fmt.Println(i, j, k)
    <span class="hljs-keyword">var</span> l, m, n <span class="hljs-keyword">int</span> = <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>
    fmt.Println(l, m, n)
    o, p, q := <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>
    fmt.Println(o, p, q)
}
</code></pre>
<p>In the above example, we are declaring and initializing variable c, d, e at once. We are declaring f, g, h and initializing them later. Similarly we are declaring i, j, k once with combining their types, basically all three will have same <code>int</code> type. Then we are declaring and initializing l, m, n at once. At the end, we are using shortcut method to declare o, p, q. These are different ways to define variables.</p>
<h3 id="heading-constants">Constants</h3>
<p>Go supports constants</p>
<pre><code class="lang-go"><span class="hljs-keyword">const</span> x <span class="hljs-keyword">int</span> = <span class="hljs-number">5</span>
</code></pre>
<p>Constants cannot be defined using <code>:=</code> and they need <code>const</code> keyword.</p>
]]></content:encoded></item><item><title><![CDATA[Hello World in Go]]></title><description><![CDATA[Go can be downloaded through the official website; click here.
Once you have installed Go, to check if go has been correctly installed, you can open a terminal and write below comand.
go version

This should show you current version of Go.
Next. Crea...]]></description><link>https://tech.latencot.com/hello-world-in-go</link><guid isPermaLink="true">https://tech.latencot.com/hello-world-in-go</guid><category><![CDATA[go download]]></category><category><![CDATA[Go Language]]></category><category><![CDATA[Hello World]]></category><category><![CDATA[hello-world-in-go]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Fri, 16 May 2025 01:22:53 GMT</pubDate><content:encoded><![CDATA[<p>Go can be downloaded through the official website; <a target="_blank" href="https://go.dev/">click here</a>.</p>
<p>Once you have installed Go, to check if go has been correctly installed, you can open a terminal and write below comand.</p>
<pre><code class="lang-plaintext">go version
</code></pre>
<p>This should show you current version of Go.</p>
<p>Next. Create a folder for your project and inside that folder, open terminal and type</p>
<pre><code class="lang-plaintext">go mod init &lt;project-name&gt;
</code></pre>
<p>this will create a go.mod file which will have a list of all your dependencies for the project. You can think of this as the package.json in Javascript / Typescript projects.</p>
<p>Create a new file with name <code>main.go</code>, inside that file, write the below code</p>
<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">main</span><span class="hljs-params">()</span></span> {
    fmt.Println(<span class="hljs-string">"Hello, World!"</span>)
}
</code></pre>
<p>Save the file, and run below command</p>
<pre><code class="lang-plaintext">go run main.go
</code></pre>
<p>OR</p>
<pre><code class="lang-plaintext">go run .
</code></pre>
<p>This should run your project and print “Hello, World!“</p>
<p>Let’s talk about each component of this file</p>
<p>The first line <code>package main</code>, tells that this file belongs to package main. Consider package as a grouping method to group multiple types, entities under one name.</p>
<p>The second line is <code>import fmt</code> which is basically an import statement. We are importing the fmt package in our file. This fmt packages allows us to do many things, one of them is printing on the console.</p>
<p>In next set of lines, we have declared a function <code>main</code>, which acts as an entry point for the application. If you change the function name with something else, you won’t be able to run the application.</p>
<p>Functions in Golang are declared using <code>func</code>. In the function we are calling the Println function from the fmt package that we imported above the main function. We are passing “Hello, World!“ to the print function. This string is then printed on the console.</p>
]]></content:encoded></item><item><title><![CDATA[Why Go!]]></title><description><![CDATA[First of all, why Go?
Go was created in 2007 at Google for following reasons

Slow Compilation: C++ and Java code at Google was too slow to compile. They needed something that could compile quickly

Complexity: Existing languages had grown to become ...]]></description><link>https://tech.latencot.com/why-go</link><guid isPermaLink="true">https://tech.latencot.com/why-go</guid><category><![CDATA[Go Language]]></category><category><![CDATA[composition]]></category><category><![CDATA[concurrency-in-go]]></category><category><![CDATA[goroutines]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Thu, 15 May 2025 14:24:17 GMT</pubDate><content:encoded><![CDATA[<p>First of all, why Go?</p>
<p>Go was created in 2007 at Google for following reasons</p>
<ol>
<li><p>Slow Compilation: C++ and Java code at Google was too slow to compile. They needed something that could compile quickly</p>
</li>
<li><p>Complexity: Existing languages had grown to become too complex. They needed something that’s simple.</p>
</li>
<li><p>Concurrency: Languages such as C++ and Java made concurrency hard to manage.</p>
</li>
</ol>
<p>Go brought some advantages as well</p>
<ol>
<li><p>Tooling: Go has great tooling support (fmt, go test, go doc)</p>
</li>
<li><p>Garbage Collection: Go’s GC makes memory management simplified.</p>
</li>
<li><p>Goroutines: Light weight threads with multiplexing.</p>
</li>
</ol>
<p>So did Google replace all its code with Golang?</p>
<p>The answer is NO!</p>
<p>Many of the languages (specifically Java) that were complex and that didn’t supported features such as concurrency, now they do, and they have pretty much simplified things.</p>
<p>So why Go?</p>
<p>Because Go is still different. Go needs minimal setup over general purpose languages like Java. Go is still fast to compile, faster to execute and fast to ship.</p>
<p>If you compare Go with scripting languages like Python and Javascript / Typescript, these scripting languages did offer rapid prototyping since the beginning. Go still has advantage over them because of concurrency.</p>
<p>If you compare Go with C++, the basic reason of using C++ was speed. However Golang is able to deliver the speeds relative to C++ with additional features and a different programming paradigm.</p>
<p>So Go is best of both worlds and hence you should be using Go.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1747318383107/3884ea5f-11e0-4520-8a75-8f5df7392a60.png" alt class="image--center mx-auto" /></p>
<p>Today, Javascript tops the charts because of it being heavily used by browsers and in web development. Java dominates the MNCs and legacy setups. Python dominates the AI space as well as backend. Go is slowly catching up being relatively new.</p>
<p>Go sits right between Java, Python, Javascript and C++. Go is a multi-paradigm (Imperative, Concurrent, Procedural) programming language.</p>
<p>Composition is a core philosophy of Go. Composition is basically building complex behavior by combining simpler types or functions. Composition is an alternative to Inheritance where you would combine multiple classes to create a complex behavior.</p>
<p>Go suggest instead of creating hierarchies of classes, just compose small reusable pieces of code.</p>
<pre><code class="lang-go"><span class="hljs-keyword">type</span> Animal <span class="hljs-keyword">struct</span> {
    Name <span class="hljs-keyword">string</span>
}

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(a Animal)</span> <span class="hljs-title">Speak</span><span class="hljs-params">()</span></span> {
    fmt.Println(a.Name, <span class="hljs-string">"makes a sound"</span>)
}

<span class="hljs-keyword">type</span> Dog <span class="hljs-keyword">struct</span> {
    Animal <span class="hljs-comment">// embedded</span>
    Breed  <span class="hljs-keyword">string</span>
}
</code></pre>
<p>In next topics, we will cover how we can use Golang to create highly scalable applications.</p>
]]></content:encoded></item><item><title><![CDATA[What are Light Weight Threads in context of Goroutines?]]></title><description><![CDATA[A thread referred as the smallest unit of execution within a process, is managed by the OS Kernel. Each Thread has its own stack i.e. its own reserved memory for its state. Depending on the Operating System, the thread stack size can vary but typical...]]></description><link>https://tech.latencot.com/what-are-light-weight-threads-in-context-of-goroutines</link><guid isPermaLink="true">https://tech.latencot.com/what-are-light-weight-threads-in-context-of-goroutines</guid><category><![CDATA[Go Language]]></category><category><![CDATA[goroutines]]></category><category><![CDATA[Threads]]></category><category><![CDATA[multithreading]]></category><category><![CDATA[concurrency]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Thu, 15 May 2025 07:26:53 GMT</pubDate><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1747293952420/8aafb4f4-6b73-4f25-9196-613fb816fe82.png" alt class="image--center mx-auto" /></p>
<p>A thread referred as the smallest unit of execution within a process, is managed by the OS Kernel. Each Thread has its own stack i.e. its own reserved memory for its state. Depending on the Operating System, the thread stack size can vary but typically falls between 1MB and 8MB.</p>
<p>Light Weight Threads often referred as User Level Threads were first conceptualized and developed in 1960s and 1970s. These are managed by a user-space library rather than the OS Kernel. The kernel isn't aware of the Light Weight Threads being created.</p>
<p>In context of Operating Systems, Light Weight Threads can have a different meaning. We are defining LWT in context of Programming Languages.</p>
<p>Light Weight Threads run above the OS Threads and their call stack is in most cases smaller than OS Threads.</p>
<p>Creating Light Weight Threads is also cheap and fast for following reasons:</p>
<ol>
<li><p>When OS creates threads, it also has to do some extra work like managing the state of the thread. Light Weight Threads are switched at user level so there is less operational overhead.</p>
</li>
<li><p>Light Weight Threads also typically have smaller stack size.</p>
</li>
<li><p>Multiple Light Weight Threads can use a single OS Level Thread. This is called as multiplexing.</p>
</li>
<li><p>Light Weight Threads enable concurrent execution of multiple tasks independently but without the overhead of OS thread management.</p>
</li>
</ol>
<p>Programming languages such as Go use light weight threads for Goroutines. Go also uses multiplexing allowing multiple Goroutines to use a single OS Thread. For e.g. in I/O-Bound operations, you can maybe run 1000+ Goroutines on a single thread while for CPU Heavy operations, the ratio of multiplexing will be lesser.</p>
<p>Depending on the Go Runtime version, Goroutines typically have an initial stack of 2kb which grows dynamically. Goroutines are handled &amp; scheduled by the Go Runtime Scheduler.</p>
<p>Java introduced virtual threads, which were lightweight threads managed by the JVM. This was introduced through Project Loom (Java 19+ Preview / Java 21+ Stable). These as well are multiplexed by the JVM, running on a small pool of carrier OS Threads.</p>
<p>Other modern languages like Kotlin, Rust (async), and Erlang also use similar lightweight threading/concurrency models.</p>
]]></content:encoded></item><item><title><![CDATA[Git Commands Practice Tutorial]]></title><description><![CDATA[Learn with me...
This is a tutorial for git commands. This should give you a basic idea of each git command specifically for interview preparation.
This tutorial assumes that you already have git installed and configured.
Basics
Create an empty folde...]]></description><link>https://tech.latencot.com/git-commands-practice-tutorial</link><guid isPermaLink="true">https://tech.latencot.com/git-commands-practice-tutorial</guid><category><![CDATA[Git]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[GitLab]]></category><category><![CDATA[Gitcommands]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Thu, 15 May 2025 02:53:05 GMT</pubDate><content:encoded><![CDATA[<p>Learn with me...</p>
<p>This is a tutorial for git commands. This should give you a basic idea of each git command specifically for interview preparation.</p>
<p>This tutorial assumes that you already have git installed and configured.</p>
<h3 id="heading-basics">Basics</h3>
<p>Create an empty folder and open terminal in that folder and type</p>
<pre><code class="lang-plaintext">git init
</code></pre>
<p>The above line will initialize your git repository.</p>
<p>Then create a file <a target="_blank" href="http://README.md">README.md</a> and write something inside that file. You can also do this via terminal itself.</p>
<pre><code class="lang-plaintext">echo "# Git Practice Repo"
</code></pre>
<p>then in the terminal, write</p>
<pre><code class="lang-plaintext">git add READMD.md
</code></pre>
<p>then write</p>
<pre><code class="lang-plaintext">git commit -m "My first commit"
</code></pre>
<p>After this, you will have to go to <a target="_blank" href="http://github.com">github.com</a>, create an empty repo and copy the https link with you.</p>
<p>In terminal, write</p>
<pre><code class="lang-plaintext">git remote add origin &lt;your-repo-url&gt;
</code></pre>
<p>Now rename your branch to "main"</p>
<pre><code class="lang-plaintext">git branch -M main
</code></pre>
<p>Now you will be pushing your file to github using below command</p>
<pre><code class="lang-plaintext">git push -u origin main
</code></pre>
<p>Now add some more changes to the READMD file, and commit</p>
<pre><code class="lang-plaintext">git commit -am "Updated READMD.md file"
</code></pre>
<p>Now push</p>
<pre><code class="lang-plaintext">git push
</code></pre>
<p>Now, go to <a target="_blank" href="http://github.com">github.com</a> and edit your <a target="_blank" href="http://READMD.md">READMD.md</a> and make some changes. Then come back to terminal, and type</p>
<pre><code class="lang-plaintext">git pull
</code></pre>
<p>This should pull the changes you made directly in github wehsite.</p>
<h3 id="heading-resetting-unstaged-commits">Resetting Unstaged Commits</h3>
<p>If you are working on this file and you haven't made any commits but you wish to restore this file back to as it was, you can use the following command.</p>
<pre><code class="lang-plaintext">git checkout -- README.md
</code></pre>
<p>Try making some changes but do not commit. And then run the above command. The file will reset to it's original state.</p>
<p>Now try to do some unnecessary changes and push the file again.</p>
<h3 id="heading-reverting-pushed-commits">Reverting Pushed Commits</h3>
<p>Previously we tried resetting the file locally. Now we will revert the commit itself. After pushing the file, use the following command</p>
<pre><code class="lang-plaintext">git revert HEAD
</code></pre>
<p>This should revert the commit and your changes are gone. This will keep the history clean as well.</p>
<p>Now to revert but keep your changes staged you can use the soft reset command</p>
<pre><code class="lang-plaintext">git reset --soft HEAD~1
</code></pre>
<p>This should reset your last commit but keep the changes staged (git add stages the changes)</p>
<p>To revert the changes as well as unstage them use the mixed flag instead of soft</p>
<pre><code class="lang-plaintext">git reset --mixed HEAD~1
</code></pre>
<p>To revert the changes as well as delete them entirely, use the hard flag instead of mixed</p>
<pre><code class="lang-plaintext">git reset --hard HEAD~1
</code></pre>
<p>Now let's create a branch. To create a branch, use the checkout command.</p>
<pre><code class="lang-plaintext">git checkout -b feature/readme
</code></pre>
<p><code>feature/readme</code> is your branch name</p>
<p>Now make some changes and commit</p>
<pre><code class="lang-plaintext">git commit -am "Updated feature/readme"
</code></pre>
<p>Now go to main branch</p>
<pre><code class="lang-plaintext">git checkout main
</code></pre>
<p>Now merge <code>feature/readme</code> into main using following command</p>
<pre><code class="lang-plaintext">git merge feature/readme
</code></pre>
<p>Once done, basically you have merged your branch locally. Now you can do git push to push the changes</p>
<pre><code class="lang-plaintext">git push
</code></pre>
<p>Then let's delete the branch</p>
<pre><code class="lang-plaintext">git branch -d feature/readme
</code></pre>
<p>This will delete the branch.</p>
<h3 id="heading-stashing">Stashing</h3>
<p>Now make some changes in your readme file and then we will stash it using below command</p>
<pre><code class="lang-plaintext">git stash
</code></pre>
<p>Stashing saves your changes without commiting them. You can restore it later. You use this command if you wish to switch between branches without commiting or any other case.</p>
<p>Now to restore the stash, use the below command</p>
<pre><code class="lang-plaintext">git stash pop
</code></pre>
<p>This should restore your changes and then you can push those.</p>
<h3 id="heading-logging">Logging</h3>
<p>Now, in the terminal type</p>
<pre><code class="lang-plaintext">git log
</code></pre>
<p>This should show you a log of commits that happened on your branch. to see more you can press the down arrow which will let you scroll down. To exit, press the <code>q</code> key.</p>
<p>To see the logs in a better way, you can add flags like following</p>
<pre><code class="lang-plaintext">git log --oneline --graph --all
</code></pre>
<p>The <code>oneline</code> flag will show you each commit with message in one line. The <code>graph</code> flag creates a graph of branches to the left. The <code>all</code> flag should show all commits.</p>
<p>Now, make some changes in the <a target="_blank" href="http://README.md">README.md</a> file and then use following command:</p>
<pre><code class="lang-plaintext">git diff
</code></pre>
<p>This command will show current changes that aren't yet committed.</p>
<p>Now, make some changes in the <a target="_blank" href="http://README.md">README.md</a> file and then check the status of the commits using following command</p>
<pre><code class="lang-plaintext">git status
</code></pre>
<p>This will show you the changes that are staged or not staged, committed or uncommitted, everything.</p>
<h3 id="heading-now-lets-talk-about-rebasing">Now let's talk about rebasing.</h3>
<p>Imagine you are working on branch1. someone merged some changes in main branch. You need those changes in branch1. So you merge main into branch1.</p>
<p>Now, if this happens multiple times, you will have multiple merges in your branch1.</p>
<p>If you finally merge branch1 into main, the main branch history will show multiple merges from main to branch1.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1747277386220/350db0da-5248-4495-b7fa-c5c8050e1ef5.png" alt class="image--center mx-auto" /></p>
<p>The above looks messier and harder to read.</p>
<p>For a cleaner approach, instead we can rebase. Rebasing in simpler words is instead of merging you simply copy main branch history into branch1 history and place branch1 history above the main copied history.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1747277403450/44a7509d-ef98-4678-a6c5-bf38172d4c03.png" alt class="image--center mx-auto" /></p>
<p>The above is much cleaner to read.</p>
<p>Let's mimic this.</p>
<h4 id="heading-merge-flow">Merge Flow</h4>
<p>in your main branch, create a file main.txt, write something in it, and then save it and commit main branch with message</p>
<pre><code class="lang-plaintext">git commit -am "Main Commit 1"
</code></pre>
<p>Now create another branch</p>
<pre><code class="lang-plaintext">git checkout -b branch1
</code></pre>
<p>Create a file branch1.txt, write this in it:</p>
<pre><code class="lang-plaintext">Branch Commit 1
</code></pre>
<p>And then save it and commit branch1 with message</p>
<pre><code class="lang-plaintext">git commit -am "Branch Commit 1"
</code></pre>
<p>Then go to main branch</p>
<pre><code class="lang-plaintext">git checkout main
</code></pre>
<p>Make some changes in text1.txt and commit</p>
<pre><code class="lang-plaintext">git commit -am "Main Commit 2"
</code></pre>
<p>Now go back to branch1</p>
<pre><code class="lang-plaintext">git checkout branch1
</code></pre>
<p>To merge main -&gt; branch1, we will write</p>
<pre><code class="lang-plaintext">git merge main
</code></pre>
<p>Then we will make some changes in branch1.txt, and then commit</p>
<pre><code class="lang-plaintext">git commit -am "Branch Commit 2"
</code></pre>
<p>Then go to main branch</p>
<pre><code class="lang-plaintext">git checkout main
</code></pre>
<p>Make some changes in text1.txt and commit</p>
<pre><code class="lang-plaintext">git commit -am "Main Commit 3"
</code></pre>
<p>Now go back to branch1</p>
<pre><code class="lang-plaintext">git checkout branch1
</code></pre>
<p>To merge main -&gt; branch1, we will write</p>
<pre><code class="lang-plaintext">git merge main
</code></pre>
<p>Then we will make some changes in branch1.txt, and then commit</p>
<pre><code class="lang-plaintext">git commit -am "Branch Commit 3"
</code></pre>
<p>Now go to main branch and merge branch1 into main</p>
<pre><code class="lang-plaintext">git merge branch1
</code></pre>
<p>Now if you try to log the main commits using following command</p>
<pre><code class="lang-plaintext">git log --oneline --graph
</code></pre>
<p>Observe the graph and the commits, this will look a bit messy.</p>
<h4 id="heading-rebase-flow">Rebase Flow</h4>
<p>in your main branch, create a file main.txt, write something in it, and then save it and commit main branch with message</p>
<pre><code class="lang-plaintext">git commit -am "Main Commit 1"
</code></pre>
<p>Now create another branch</p>
<pre><code class="lang-plaintext">git checkout -b branch1
</code></pre>
<p>Create a file branch1.txt, write this in it:</p>
<pre><code class="lang-plaintext">Branch Commit 1
</code></pre>
<p>And then save it and commit branch1 with message</p>
<pre><code class="lang-plaintext">git commit -am "Branch Commit 1"
</code></pre>
<p>Then go to main branch</p>
<pre><code class="lang-plaintext">git checkout main
</code></pre>
<p>Make some changes in text1.txt and commit</p>
<pre><code class="lang-plaintext">git commit -am "Main Commit 2"
</code></pre>
<p>Now go back to branch1</p>
<pre><code class="lang-plaintext">git checkout branch1
</code></pre>
<p>To rebase main -&gt; branch1, we will write</p>
<pre><code class="lang-plaintext">git rebase main
</code></pre>
<p>Then we will make some changes in branch1.txt, and then commit</p>
<pre><code class="lang-plaintext">git commit -am "Branch Commit 2"
</code></pre>
<p>Then go to main branch</p>
<pre><code class="lang-plaintext">git checkout main
</code></pre>
<p>Make some changes in text1.txt and commit</p>
<pre><code class="lang-plaintext">git commit -am "Main Commit 3"
</code></pre>
<p>Now go back to branch1</p>
<pre><code class="lang-plaintext">git checkout branch1
</code></pre>
<p>To rebase main -&gt; branch1, we will write</p>
<pre><code class="lang-plaintext">git rebase main
</code></pre>
<p>Then we will make some changes in branch1.txt, and then commit</p>
<pre><code class="lang-plaintext">git commit -am "Branch Commit 3"
</code></pre>
<p>Now go to main branch and merge branch1 into main</p>
<pre><code class="lang-plaintext">git merge branch1
</code></pre>
<p>Now if you try to log the main commits using following command</p>
<pre><code class="lang-plaintext">git log --oneline --graph
</code></pre>
<p>Observe the graph and the commits, those will look cleaner than the merge.</p>
<h4 id="heading-for-interactive-rebasing">For interactive rebasing</h4>
<p>you can use an extra flag <code>-i</code> like below</p>
<pre><code class="lang-plaintext">git rebase main -i
</code></pre>
<p>This will open up an editor with instructions allowing you to make changes allowing you to squash or pick commits. Squashing is combining multiple commits into one.</p>
<h3 id="heading-alias">Alias</h3>
<p>You can create alias for commands to make them shorter</p>
<pre><code class="lang-plaintext">git config --global alias.st status
</code></pre>
<p>So next time, you will be calling status command using</p>
<pre><code class="lang-plaintext">git st
</code></pre>
<p>That's all.</p>
]]></content:encoded></item><item><title><![CDATA[IPv6 vs IPv4: The Basic Difference]]></title><description><![CDATA[There are 2 trillion galexies in the observable universe and each galaxy might have about 100 billion starts.
Let's assume each of those stars have a habitable planet, and each habitable planet has 10 billion intelligent people just like us.
Now, if ...]]></description><link>https://tech.latencot.com/ipv6-vs-ipv4-the-basic-difference</link><guid isPermaLink="true">https://tech.latencot.com/ipv6-vs-ipv4-the-basic-difference</guid><category><![CDATA[IPv4]]></category><category><![CDATA[ipv6]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Wed, 14 May 2025 02:51:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1747190949779/73ffb7e5-b15e-4475-b1fc-79a5bd23441f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>There are 2 trillion galexies in the observable universe and each galaxy might have about 100 billion starts.</p>
<p>Let's assume each of those stars have a habitable planet, and each habitable planet has 10 billion intelligent people just like us.</p>
<p>Now, if we had to map everyone to a common internet or a common IP system;</p>
<p>There are 2 trillion galaxies x 100 billion stars x 10 billion individuals = 10^34 people</p>
<p>To map each of those on to an IP system we will need;</p>
<pre><code class="lang-plaintext">2^n &gt;= 10^34 

⇒ n ≥ log₂(10³⁴) ≈ 34 × log₂(10) ≈ 34 × 3.3219 ≈ 113 bits
</code></pre>
<p>So we will need an IP system of 113 bits.</p>
<p>IPv4 is about 32 bits so it can cover about ~4.3 billion people. Also due to segmentation and reservations, the range reduces to roughly 3.7 billion.</p>
<p>IPv6 is of 128 bits. So IPv6 can cover addresses for all galaxies in the observable universe and you will still have some room left.</p>
<p>Turns out, IPv6 isn't just future-proof for Earth. It's galactic-level ready.</p>
]]></content:encoded></item><item><title><![CDATA[Which programming language / framework should you learn as a Fresher?]]></title><description><![CDATA[I did an experiment, correct or wrong, you all are to judge.
I went to specific language / framework websites from where they could be installed. Then I copied the root url and pasted it into look up websites (this one: ) and hit lookup. Following we...]]></description><link>https://tech.latencot.com/which-programming-language-framework-should-you-learn-as-a-fresher</link><guid isPermaLink="true">https://tech.latencot.com/which-programming-language-framework-should-you-learn-as-a-fresher</guid><category><![CDATA[Java]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[Rust]]></category><category><![CDATA[Python]]></category><category><![CDATA[Go Language]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Tue, 13 May 2025 09:30:04 GMT</pubDate><content:encoded><![CDATA[<p>I did an experiment, correct or wrong, you all are to judge.</p>
<p>I went to specific language / framework websites from where they could be installed. Then I copied the root url and pasted it into look up websites (this one: ) and hit lookup. Following were the results for each of them.</p>
<p>Node.js: 4lac+ visitors<br />Python: 1.3million+ visitors<br />Java: 4.7million+ visitors<br />Go: 4,000+ visitors<br />Rust: 67,000+ visitors</p>
<p>Golang and Rust were a surprise. Now I went to Naukri.com and searched the above languages into jobs.</p>
<p>Node.js: 1lac+ jobs<br />Python: 50,000+ jobs<br />Go: 1lac+ jobs<br />Java: 6,000+ jobs<br />Rust: 1lac+ jobs</p>
<p>Java was a shock, python as well. Then I searched Django and Flask instead of python and Springboot and Hibernate instead of Java. For both the cases, I got 1lac+ jobs this time.</p>
<p>So Naukri search results didn’t made sense.</p>
<p>Then I went to indeed. Following were the results</p>
<p>Node.js: 7,000+ jobs<br />Python: 29,000+ jobs<br />Go: 800+ jobs<br />Java: 25,000+ jobs<br />Rust: 200+ jobs</p>
<p>This time the numbers were different.</p>
<p>While just 2 job sites won’t tell the actual statistics, the number of visitors on each of the language’s official website can tell that how many new users are downloading that specific language.</p>
<p>If we see Golang, it has highest number of jobs per number of visitors, then follows Python, then Node.js, then Rust, and at the end, there is Java. That’s what this experiment concludes.</p>
<p>If you see more jobs for a particular language, that doesn’t mean you should learn that language. You should also be looking at how many people are learning that language. If those as well are more, then learning that language makes less sense as you will have more competition.</p>
<p>But if a language or a framework has less jobs but even less developers, then it should be easier to get a job for that language.</p>
<p>For more accurate stats regarding languages, also checkout stack overflow survey: <a target="_blank" href="https://survey.stackoverflow.co/2024/technology">https://survey.stackoverflow.co/2024/technology</a></p>
<p>That’s it for now…</p>
]]></content:encoded></item><item><title><![CDATA[Startups were meant to make life convenient but now making it more difficult.]]></title><description><![CDATA[Quick Commerce apps make UI such that;

For some there is an apply free delivery button which is by default checked out even if you pay premium

Some send stale food. Some send bad quality of products and then they refuse to refund.


PG Apps ask you...]]></description><link>https://tech.latencot.com/startups-were-meant-to-make-life-convenient-but-now-making-it-more-difficult</link><guid isPermaLink="true">https://tech.latencot.com/startups-were-meant-to-make-life-convenient-but-now-making-it-more-difficult</guid><category><![CDATA[zepto]]></category><category><![CDATA[swiggy]]></category><category><![CDATA[Quick Commerce]]></category><dc:creator><![CDATA[Sankalp pol]]></dc:creator><pubDate>Mon, 12 May 2025 05:28:08 GMT</pubDate><content:encoded><![CDATA[<p><strong>Quick Commerce</strong> apps make UI such that;</p>
<ol>
<li><p>For some there is an apply free delivery button which is by default checked out even if you pay premium</p>
</li>
<li><p>Some send stale food. Some send bad quality of products and then they refuse to refund.</p>
</li>
</ol>
<p><strong>PG Apps</strong> ask you for deposit and never refund.</p>
<p><strong>Hotel Booking Apps</strong> confirm your stay a week back and when you reach your hotel, you are either forced to pay more at reception, or you have to look for other options, with trolly bags in your hand in a unknown city.</p>
<p>Cab Drivers use <strong>Ride Apps</strong> to accept booking but then they will call you and ask for higher price,</p>
<p><strong>Online Packers and Movers</strong> provide you with insurance for products for high premium but you are never able to claim that.</p>
<p><strong>Broadband services</strong> take weeks to send someone to fix connectivity issues.</p>
<p>These were real problem statements but the solutions are screwed up with no empathy towards people.</p>
<p>For most of the cases, the companies are at fault.</p>
<p>But for some cases, people are at fault as well. For e.g. unnecessarily placing refund orders even if the item is good. The company makes losses because of this, and now if someone genuinely needs refund but they might not get it.</p>
<p>I think <strong>offline is better</strong>.</p>
<p>I can call a hotel owner and confirm prices and stay. I can go to local vegetable vendor and check the quality of vegetables before buying. I can connect with a local transport service which might not be better but would be definitely cheaper and it at least not sell false promises at higher costs.</p>
<p>The belief with technology was that <strong>competition could've fostered better services</strong>, more employment could've been generated. But that hasn't happened.</p>
<p>What do you think can fix these issues?</p>
<p>I believe the root of the problem does indicate the <strong>civic sense</strong> of people. If the companies realise their responibility towards people and if people stop exploiting systems built for their own good, then maybe we will be able to solve this problem.</p>
<p>But that's a long road ahead, and that's the only solution from my perspective. Going offline doesn't make sense because problems existed first in offline business and then those were promised to be fixed by technology which it didn't.</p>
<p>That's it for now.</p>
]]></content:encoded></item></channel></rss>