Programming with go!
How to start programming with Go
Hello guys it’s crazyc4t once again, sorry for being a bit distant on my blog but prepare yourselves because there’s more content in the oven!
I disappeared but with a purpose, I was laser-locked focused learning go! And it is really fun, but first…
What is go?
Go is an open-source programming language supported by Google, created by Ken Thompson and Rob Pike, the creators of the UNIX operating system, made for Google-sized problems, being Go a static fast-compiled language, that includes native concurrency, garbage collection and efficiency at scale.
Why go?
Go is a programming language easy to pick up and get started with (as we are going to do in this post!) and easier if you come from other programming languages, it’s syntax is similar to C, it has built-in concurrency and a robust standard library, the go community is growing as time passes and it features tons of modules, libraries, tools to play with and documentation to learn from like this one!
Go is used for Google-sized problems, making FAANG interested in go, these are companies that use go to power their software:
- PayPal
- American Express
- Microsoft
- Meta
- Twitch
- Tweeter
- Netflix
And so much more companies as well are joining the list since is really easy to pick up and the safety+speed concept that helps them right quality code, and make debugging really easy, since the compiler lints the errors you have in your code before you even compile it!
Go is used on different code purposes like:
- Cloud & network services
- Command-line interfaces
- Web development
- DevOps
Projects that were built with go are:
- Docker
- Kubernetes
- Hugo
- Cockroach DB
- Gophish
- Arduino-CLI
- Github-CLI
Getting started with go!
We need to setup our coding environment to code with go, first we need to install it.
Installation of go
- Linux:
- Debian/Ubuntu:
sudo apt install golang
- RHEL/Fedora:
sudo dnf install go
- Arch BTW:
sudo pacman -S go
- Debian/Ubuntu:
- Windows & macOS:
- Go to this website and install the binary: https://go.dev/dl
That’s it! Check if you have it installed by checking it’s version: go version
Setting up your text editor
You can use any type of text editor you want but my personal recommendation is:
- VSCodium (VSCode FOSS binary)
- Install the go extension
- Neovim
- Install the “gopls” LSP and the “gofmt” formatter using your favorite LSP installer (lsp-installer, mason.nvim)
- Jetbrains’s Goland
Write some code!
Hello world!
1// Print hello world!
2
3package main
4// meaning that it should be compiled as a executable program, not as a shared libary
5
6import "fmt" // The format package from the standard libary for printing the string
7
8func main() {
9 fmt.Println("Hello Gopher!")
10}
After coding you can run it by just doing so:
go run main.go
Or you can compile it for your system!
go build main.go
Let’s make a greeter!
1package main
2
3import "fmt"
4
5func main() {
6 fmt.Println("Hello! What's your name? ")
7 var name string // creating a variable without a value of type string
8 fmt.Scanf("%s", &name) // Scan the input text and format it determined by the type
9 fmt.Println("Hello", name, "How are you doing?")
10}
After scratching the surface of go, this is the next step…
Keep learning!
These are some resources that are awesome!
Webpages
Tutorials
- TechWorld with Nana Go for beginners
- FreeCodeCamp 7-hour Go tutorial
- Go programming: The complete developer’s guide (It’s a udemy course)
Exercises
Books
Thank you for reading!
I’m learning go at the moment so expect more go content coming your way!