Go

Learning Go with goByExample

In this post, I will write my findings while learning Golang with this well known website https://gobyexample.com/.

This is my first time learning the language and my first post about it, so, it is going to be a pretty junior level post.

My mind works better when I study and type down what I'm learning, so, I hope you don't find annoying if the examples in this post are related to that website, since that's what I will be doing, reading, learning, typing & testing code on idle and saving code examples in this post.

Why Golang?

I have heard of Golang for a while, checking it out and seeing how industry has been adapting it heavily made me think about it and investigate it. Basically what I like the most is its good performance for big task against node, python and other BE languages. So, here I'm, I would like to give a shot.

Run/Build

//Run
go run my-go-program.go

//Build
go build my-go-program.go

//Excute builded program
./my-go-program

Hello world

Classic one.

package main
    
import "fmt"
    
func main(){
   fmt.Println("Hello world")
}

so, in line 1 we can see the package name, as my understanding, every go program needs to have a main package to run.

In line 3, we have and import called fmt that according to packaged documentation https://pkg.go.dev/fmt it implements a formatted I/O with functions like printf and scanf. This package is used frequently for printing

In line 5 we write our function, in line 6 we print a new line using Println function.