Learning Go
Go and Rust are the two programming languages I’m interested right now as they are up and coming in the industry and beloved by their users, the gophers and the rustaceans. I’ve dipped my toes into Rust and I like the verboseness and the compiler so now it’s time to give Go a try.
Part 1: Installation and Hello World
Go is very easy to install (currently on Windows), just run the appropriate installer from https://go.dev/dl/ and you’re ready to “go”. No need to configure path variables or anything. After the installer finished I just typed go version
in a terminal and everything was ready.
As always, the first thing to do with a new programming language is the hello world. I installed GoLand by JetBrains but before going into a full fledged IDE that will handle project and module creation on its own I had to do things manually to understand Go’s philosophy.
I followed the official documentation to get started. I installed the official Go extension for VSCode and created a folder called “GoProjects”. Inside GoProjects I created the directory “testProject” and inside it, as per the documentation I run go mod init testProject
and a go.mod file was created for me with the contents:
module testProject
go 1.18
I opened the directory in VSCode and added the file “hello.go”. I manually typed the code and when I entered in the console the command go run .
a nice error greeted me: package testProject is not a main package
. See I was being smart (and dumb as it turns out), the tutorial’s first line is package main
, but I thought to myself “I named the project testProject so I’ll give the package the same name”, which sounded normal to me coming from namespaces and java packages.