<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Thành Đoàn Nhật</title>
    <description>The latest articles on DEV Community by Thành Đoàn Nhật (@ethan_doannhatthanh).</description>
    <link>https://dev.to/ethan_doannhatthanh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3969282%2F440d6794-1b7d-4442-886a-63cf329cee27.jpeg</url>
      <title>DEV Community: Thành Đoàn Nhật</title>
      <link>https://dev.to/ethan_doannhatthanh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ethan_doannhatthanh"/>
    <language>en</language>
    <item>
      <title>Golang Day 2: Arrays, Slices and Maps</title>
      <dc:creator>Thành Đoàn Nhật</dc:creator>
      <pubDate>Mon, 08 Jun 2026 16:25:08 +0000</pubDate>
      <link>https://dev.to/ethan_doannhatthanh/golang-day-2-arrays-slices-and-maps-4gda</link>
      <guid>https://dev.to/ethan_doannhatthanh/golang-day-2-arrays-slices-and-maps-4gda</guid>
      <description>&lt;p&gt;Today, I learned about various types of collections in Go, because processing collection of data is one of the most common tasks in programing, such as data from files, from response API or from anything. &lt;br&gt;
Since this is my current understanding, so if I have any mistake or you have additional insights, please leave a comment, I would really appreciate it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arrays
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Overall
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Arrays form the base data structure for both slices and maps.&lt;/li&gt;
&lt;li&gt;An array is a fix-length data type that contains a contiguous block of elements of the same type. This could be a built-in type such as integer and strings, or it can be a struct type. Because of this, the data of memory can stay in CPU caches longer, and we can retrieve data in array quickly. Since all elements in arrays have the same type and size, Go can calculate memory address of any elements directly from its index. This allow constant-time access (O(1)). 
#### Declaring and initializing&lt;/li&gt;
&lt;li&gt;Array declare by specifying the type of data to be stored and total number of elements required, known as length of array.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Declare integer array with length is 5&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can't modify both type of element which stored in array and length of array after declare, so if we want to store in longer array, we need to create new array with target length, and copy all elements from old array to it.&lt;/li&gt;
&lt;li&gt;We can declare array by literal, and this is a idiomatic in Go.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Declare an integer array of 5 elements&lt;/span&gt;
&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;Note&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt; &lt;span class="n"&gt;cannot&lt;/span&gt; &lt;span class="n"&gt;declare&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;_int_&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="n"&gt;initialize&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt; &lt;span class="n"&gt;_string_&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;raise&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="n"&gt;when&lt;/span&gt; &lt;span class="n"&gt;editor&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
&lt;span class="c"&gt;// Declare an integer array of 5 elements but not specific number elements, Go automatically get that info from list value initializing&lt;/span&gt;
&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;// Declare an integer array of 5 elements, but we just define 2 first element, so rest of array will store zero value of array's type.&lt;/span&gt;
&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;In&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Working with array
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;To access individual element by index, we use []. Ex: array[2] &lt;/li&gt;
&lt;li&gt;We can have an array of pointers, we use * to access value that pointer points to.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Declare an array of pointers&lt;/span&gt;
&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; 
&lt;span class="c"&gt;// Assign value to pointer at index 1&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;
&lt;span class="c"&gt;// Because we don't initialize value for rest of array, it will be zero value of pointer - nil.&lt;/span&gt;
&lt;span class="c"&gt;// fmt.Println(array) -&amp;gt; [&amp;lt;nil&amp;gt; 0x2a73258360d0 &amp;lt;nil&amp;gt; &amp;lt;nil&amp;gt; &amp;lt;nil&amp;gt; 0x2a73258360d8]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Array is a value in Go, so we can assign it to other arrays, but that arrays need to same element's type and same length, if not, this raise error compiler.&lt;/li&gt;
&lt;li&gt;Similar, copy an pointer array will copy all pointer from source array, not copy value of pointers point to.&lt;/li&gt;
&lt;li&gt;We can create nested array, array contains array, this allow us to can create multidimensional array.
#### Passing array between functions&lt;/li&gt;
&lt;li&gt;When we passing array between functions, it always passed by value. This mean we will copy all value of array, regardless entirely type of elements and size of array, for large arrays, it not effective for both memory and performance.&lt;/li&gt;
&lt;li&gt;In case large arrays, we should pass pointer of array between function, because we just pass address of array, not entire array, but when do it, we also aware that when we modify value of element of array, outer function will impact.
## Slices
#### Overral&lt;/li&gt;
&lt;li&gt;Slices are built around the concept of dynamic arrays, that can be modify size quickly. Underlying in memory of slice is contiguous block, so it offer you all benefit of indexing, iteration and garbage collection.&lt;/li&gt;
&lt;li&gt;Slices have three metadata field: pointer address (pointer to underlying memory) , length and capacity.
#### Declare&lt;/li&gt;
&lt;li&gt;We can declare a slice by &lt;em&gt;make&lt;/em&gt; function, specific length and capacity of slice (if capacity not specific, it could be same with length)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;slice&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="n"&gt;slice_specific_cap&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;An idiomatic way of creating a slice is to use a slice literal. It quite similar with array literal, except we don't put length of slice in [], the length and capacity are based on length of values that we initializing
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt; &lt;span class="n"&gt;slice&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sc"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'b'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'c'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can specific index of initial value, similar array:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;slice&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;99&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="sc"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Note: when we put length in [], we create an array, if not, we create a slice&lt;/li&gt;
&lt;li&gt;Create nil slice: var slice []int&lt;/li&gt;
&lt;li&gt;Create zero slice: slice := make([]int, 0) or []int{}
#### Working with slice&lt;/li&gt;
&lt;li&gt;I think it similar in list in Python, about index, changing share memory,.. but I notice that create slice from source slice have something to be aware.&lt;/li&gt;
&lt;li&gt;Create new slice for exists slice. Ex:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt; &lt;span class="n"&gt;sliceSrc&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="n"&gt;sliceNew&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;slice_src&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c"&gt;// [1, 2]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, length of sliceNew is 2, but capacity of it is 4.&lt;br&gt;
We have notice: for slice[i:j] with an underlying array of capacity k&lt;br&gt;
length: j - i (3 - 1 = 2)&lt;br&gt;
capacity: k - i (5 - 1 = 4)&lt;br&gt;
Because this behavior is just create new slice from an exists underlying array, slice_new have pointer points to element index 1 in  sliceSrc. So, if we modify index 1 in sliceSrc, the value of pointer 0 of sliceNew pointing will be change, similar potential problem of copy array in Python&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Growth of slice: one of the advantage of using a slice over an array is that we can growth the capacity of our slice as needed. We do this by using built-in function append.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;slice&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;newSlice&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that append a slice can change value of exists underlying array, because it is contiguous block in memory.&lt;br&gt;
When base capacity doesn't enough for new value, Go automatically create new underlying array with exist value, and growth the capacity of new underlying array, based on current number( if number under 1000, it will be 2, and if number greater 1000, it will be 1.25 and this is just current rule)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Because of potential issue when append value to new slice, we can protect it by third index when assign new slice.
newSlice := oldSlice[2:3:4]
newLength: 3 - 2 = 1
newCapacity: 3 - 2 = 1
In this case, newSlice has newLength and newCapacity is 1, because of this, when we call append for newSlice to add new value, Go need to create new underlying array, and we will prevent any potential bug from sharing underlying array.
Notice that we can't create new capacity large than capacity of exist slice, it will raise runtime error.&lt;/li&gt;
&lt;li&gt;We can append multiple value to a slice with one call.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;or&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sliceOther&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Iterate slice: for index, value := range slices. Range will return two value, index and value of this index. Value return is copy of the value, not referrence.&lt;/li&gt;
&lt;li&gt;We also iterate a slice by for index, similar other language:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Passing slice between functions
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;When we pass slice between functions, it requires nothing more than passing the slice by value because we just copy the slice pass to function, not contains underlying array, and because of this, need to be careful when change value of underlying array.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Maps
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Overall
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A maps is a data structure similar dict in Python, store collection of data by key/value pairs. A maps is unorder, although we store in same order, the order of pair when we iterate always different. Maps use hash tables internal. A hash table of key helps determine where key/value pairs stored and located efficiently. Because of this, key of maps require hashable, that mean it always return same value when hash every time (int, string, .. not slices, maps and function)
#### Declare&lt;/li&gt;
&lt;li&gt;We can use map function or literal maps
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt; &lt;span class="c"&gt;// Declare use map function&lt;/span&gt;
&lt;span class="n"&gt;maps&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="c"&gt;// Declare use maps literal&lt;/span&gt;
&lt;span class="n"&gt;dict&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"a"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"b"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Working with maps
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A nil map can't use to store key/value pairs, but zero map can use.&lt;/li&gt;
&lt;li&gt;Get value of key in maps can return two value: value and flag exists key. When key exists, it return value and True, but when key not exists, value return zero values of map value and False for flag exists key.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exists&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;maps&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"key"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can assign a key/value pair to maps by : maps[key] = value&lt;/li&gt;
&lt;li&gt;We can remove a key/value pair in maps by: delete(maps, key), and if key is not exists, it will not raise any error.&lt;/li&gt;
&lt;li&gt;Iterate maps return key and value for each pair
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;maps&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Passing maps between functions
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Maps are pass by value. However, the copied hash value still refers to underlying hash table, so modify maps in function also make caller maps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So this is some main point I learn about arrays, slices and maps in Go. I feel they quite similar concept in Python, but have some new concepts about capacity of underlying arrays.&lt;br&gt;
Thank you for take time to read my blog. Good luck for your journey!&lt;/p&gt;

</description>
      <category>go</category>
      <category>learning</category>
    </item>
    <item>
      <title>Golang Day 1: Introduce</title>
      <dc:creator>Thành Đoàn Nhật</dc:creator>
      <pubDate>Sun, 07 Jun 2026 05:13:56 +0000</pubDate>
      <link>https://dev.to/ethan_doannhatthanh/golang-day-1-introduce-1gme</link>
      <guid>https://dev.to/ethan_doannhatthanh/golang-day-1-introduce-1gme</guid>
      <description>&lt;p&gt;Today, I started learning Go(Golang), and I want to note down some key concepts that I think are important to understand and remember.&lt;br&gt;
Since this is based on my current understanding, there may be mistakes. If you notice any, please leave a comment, I would really appreciate your feedback.&lt;/p&gt;

&lt;p&gt;When I was looking at backend developer job postings, I noticed that Go is frequently listed as a required or preferred programming language. This is true for both startups or well-established technology companies. That led me to a question: &lt;strong&gt;Why do so many developers choose Go for new projects?&lt;/strong&gt; &lt;br&gt;
After researching various resources and books, I found that Go has become increasingly popular because it addresses modern software development challenges. &lt;br&gt;
When choosing a programming language for new project, there are usually trade-offs between development speed (such as Python), execution performance (such as C or C++) and team familiarity.&lt;br&gt;
Go sits somewhere in the middle of these competing priorities by offering both rapid development and strong performance.&lt;/p&gt;

&lt;p&gt;Here are some features that I believe contribute to Go's growth in the software industry.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Concise syntax: Go has simple and concise syntax with relatively few keywords to learn. Because of this, new developers can become productive quickly and focus more in solving problems rather than learning complex language features.&lt;/li&gt;
&lt;li&gt;Fast compilation: Go's compiler is known for its speed. Instead of waiting a long time for a project compile, especially in large codebases, developers can build and test their applications quickly. This helps improve productivity and shortens the development feedback loop.&lt;/li&gt;
&lt;li&gt;Efficient Resource Utilization: Go can efficiently utilize modern hardware resources because it has built-in support for concurrency. Go provides &lt;strong&gt;gorountines&lt;/strong&gt;, which are lightweight thread managed by the Go runtime. Goroutines requires significantly less memory than operating system threads, and it easy to create and manage. Go also provides &lt;strong&gt;channels&lt;/strong&gt;, which allow goroutines to communicate safely. Channels helps reduce the complexity of sharing data between concurrent tasks and can prevent some common synchronization issues. &lt;/li&gt;
&lt;li&gt;Garbage Collection: Go includes a garbage collector, which automatically manages memory allocation and deallocation. This significantly reduces the risk of memory-related problems and allows developers to focus more on business logics. Although garbage collection introduces some runtime overhead, it is often acceptable trade-off for improved productivity and reliability. I once experienced application crashes in C++ due to management memory mistakes, so I personally find this trade-off worthwhile.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are some of the main reasons I found while researching why Go has become popular in software industry. It combines ease of development, good performance and strong support for concurrent programing, making it a compelling choice for many backend systems or cloud-native applications.&lt;br&gt;
If I have misunderstood anything or you have additional insights, please leave a comment. I would greatly appreciate for your feedback.&lt;br&gt;
Thank you for taking the time to read my blog, and good luck on your learning journey!&lt;/p&gt;

</description>
      <category>go</category>
      <category>learning</category>
    </item>
    <item>
      <title>First blog: My journey was started</title>
      <dc:creator>Thành Đoàn Nhật</dc:creator>
      <pubDate>Fri, 05 Jun 2026 07:47:24 +0000</pubDate>
      <link>https://dev.to/ethan_doannhatthanh/first-blog-my-journey-was-started-1n4o</link>
      <guid>https://dev.to/ethan_doannhatthanh/first-blog-my-journey-was-started-1n4o</guid>
      <description>&lt;p&gt;Hello everyone, my name is Ethan and I from Vietnam. I am a Backend Engineer with over 5 years of experience, mainly developing with Python and hand-on Golang in about 1 year. I focus on developing and building scalable and distributed system using FastAPI, Flask and Sanic. I worked with event-drivent architecure using Kafka and Pulsar to handle message queue. I know use Redis, PostgreSQL, MySQL, MongoDB,… I am interested with AI-power or Intelligence System, so I have skills about AI, Machine Learning (I am actually train model myself) and have knowledge of AI, include embedding, training, score, evaluation,…&lt;/p&gt;

&lt;p&gt;Recently, I am looking for a new opportunity for Backend or AI Engineer in Ho Chi Minh City but that have some difficulties. I see that the IT market is highly competitive, thanks for the rapid growth of AI technologies, and impact from downly economic in the world. So I build that blog to improve my skills include technical skills (I think i will learn Golang seriously) and English skills (I really want to work in international environment to explore my mind, not just my eye). &lt;/p&gt;

&lt;p&gt;Because my english is weak, I very appreciate with people help me to fix and improve it, although i know that my words are terrible, sometime not right meaning, but I think that the best way to improve these skill is practice and practice. &lt;/p&gt;

&lt;p&gt;Thanks for you to read my first blog, good luck to you!&lt;/p&gt;

&lt;p&gt;*** If you have any questions about me or my beautiful country - Vietnam, you can contact me by email: &lt;a href="mailto:dnthanh0207@gmail.com"&gt;dnthanh0207@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>english</category>
    </item>
  </channel>
</rss>
