A few random facts about Go

A few random facts about Go for someone coming from a different language that were eye opening for me:

  • There are no optional method arguments, none, nil - every method accepts a number of required arguments or none at all, there are variadic functions though accepting a list of arguments of undefined length
  • Variables can be passed around by reference or copy, it's an important distinction
  • Public variables or functions are defined using uppercase, private variables/functions are defined using lowercase - simple as that
  • Go isn't exactly an OO language, a protected access modifier is nowhere to be found
  • Public and private variables are scoped to a module
  • A module is simply a directory with files - when you need a new module you simply create a new directory within your project
  • There are two kinds of modules in Go: a library module that can be imported in other modules using import "mypackage" syntax and a main module with a main.go file, which is the entry point to a program
  • Goroutines allow to do tasks concurrently (the famous feature of Go), from my experience when just starting a lot can be accomplished without using concurrency patterns, goroutines can be gradually introduced when necessary
  • All errors need to be handled where they occur 😲, there are no exceptions in Go - this takes some time to get used to
  • The current preferred way to manage dependencies is to use a combination of go.mod/go.sum files
  • Go is a statically typed, compiled language - each program compiles to a single binary (compare that with thousands of files in a typical interpreted program)
  • The compiler is strict - there can be no unused imports, no unused variables - this can be quite frustrating when trying to go fast 🚀, goimports helps to automate adding missing import lines and removing unreferenced ones, there's a nice integration in VS Code