My First Week Learning Go


A week ago i started learning Golang, I wanted to share my experiences and key takeaways from this exciting first week. If you're considering learning Go or are just starting out yourself, this might give you a peek of what to expect.
Why I chose GO
let me briefly explain why i chose go. Lately Go language has been gaining a tremendous popularity for its simplicity and performance. Created By google the language promises to be powerful and approachable - perfect for building applications , especially in terms of backend and cloud infrastructure.
Day 1-2 : Setting up and Hello World
Getting Go installed is surprisingly straightforward. The official go website provides clear installation instructions , within minutes , i had go running in my machine.
the traditional “Hello, World“ programme looks like this:
Every Go Programs starts with a package declaration, and executable program must have a main
package with a main function. The import
statement brings in necessary packages – in this case, fmt
for formatted I/O operations.
Note:
Note 1: Once a variable is declared in Go, it MUST be used. If you declare a variable and don't use it anywhere in your code, the compiler will throw an error. This was frustrating at first when debugging, but it forces you to write cleaner code.
Note 2: Similarly, all imported packages must be used. Import something you don't need? Compilation error! This strictness keeps your code lean and dependency-free.
Day 3-4: Variables , Types , and Basis Syntax
Go's type system felt both familiar and refreshingly explicit. I learned about Go's basic types:
Numeric types:
int
,int8
,int16
,int32
,int64
,uint
,float32
,float64
String type:
string
Boolean type:
bool
Variable declarations in Go can be done in multiple ways:
var fullName string = "John"
var age int = 25
//or using short declaration
name := "John"
age := 25
Day 5: Functions and Control Structures
func add(a int, b int) int {
return a + b
}
// Multiple return values - a Go specialty!
func divide(a, b float64) (float64, error) {
if b == 0 {
return 0, fmt.Errorf("cannot divide by zero")
}
return a / b, nil
}
The ability to return multiple values from functions is something I found incredibly useful. Error handling in Go is explicit – functions that might fail typically return an error as their last return value.
Control structures in Go are straightforward:
// if statements
if age >= 18 {
fmt.Println("Adult")
} else {
fmt.Println("Minor")
}
// for loops (Go's only looping construct)
for i := 0; i < 10; i++ {
fmt.Println(i)
}
// switch statements
switch day {
case "Monday":
fmt.Println("Start of work week")
case "Friday":
fmt.Println("TGIF!")
default:
fmt.Println("Regular day")
}
Day 6-7: Arrays, Slices, and Maps
This is where Go started to show its unique character. While arrays exist in Go, slices are much more commonly used:
// Array (fixed size)
var arr [5]int = [5]int{1, 2, 3, 4, 5}
// Slice (dynamic)
var slice []int = []int{1, 2, 3, 4, 5}
slice = append(slice, 6) // Adding elements
Slices are incredibly powerful and flexible. They're essentially dynamic arrays that can grow and shrink as needed. The append
function became essential for working with slices.
Maps in Go are similar to dictionaries or hash tables in other languages:
ages := make(map[string]int)
ages["Alice"] = 30
ages["Bob"] = 25
// Or initialize directly
scores := map[string]int{
"Alice": 95,
"Bob": 87,
"Carol": 92,
}
// Check if key exists
age, exists := ages["Charlie"]
if exists {
fmt.Println("Charlie's age:", age)
} else {
fmt.Println("Charlie not found")
}
Challenges I Faced
The biggest adjustment was getting used to Go's explicit error handling. Coming from languages with try-catch blocks, the pattern of checking if err != nil
after function calls felt repetitive at first, but I'm beginning to appreciate its clarity.
Another challenge was the learning curve around slices versus arrays, and understanding when to use each (though slices are almost always the answer for beginners).
If you're thinking about learning Go, I'd encourage you to take the plunge. The language's growing ecosystem, excellent tooling, and strong community make it an excellent choice for both beginners and experienced developers looking to expand their skillset.
You can find all the code at:https://github.com/atharva-patil-23/intro_golang
Subscribe to my newsletter
Read articles from Atharva Patil directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
