Summary: I’ve presented an introduction to Go a few times for developers who are new to the language – this is that talk serialized as a technical article. It looks at why you might want to use Go, and gives a brief overview of the standard library and the language itself.

A few years ago I learned Go by porting the server for my Gifty Weddings side gig from Python to Go. It was a fun way to learn the language, and took me about “two weeks of bus commutes” to learn Go at a basic level and port the code.

Since then, I’ve really enjoyed working with the language, and have used it extensively at work as well as on side projects like GoAWK and zztgo. Go usage at Compass.com, my current workplace, has grown significantly in the time I’ve been there – around half of our 200 plus services are written in Go.

This article describes what I think are some of the great things about Go, gives a very brief overview of the standard library, and then digs into the core language. But if you just want a feel for what real Go code looks like, skip to the HTTP server examples.

Why Go?

As the following Google Trends chart shows, Go has become very popular over the past few years, partly because of the simplicity of the language, but perhaps more importantly because of the excellent tooling.

Google Trends data for "golang" from 2010 to 2020

Here are some of the reasons I enjoy programming in Go (and why you might like it too):

  • Small and simple core language. Go feels similar in size to C, with a very readable language spec that’s only about 50 pages long (compared to the Java spec’s 770 pages). This makes it easy to learn or teach to others.
  • High quality standard library, especially for servers and network tasks. More details below.
  • First class concurrency with goroutines (like threads, but lighter) and the go keyword to start a goroutine, channels for communicating between them, and a runtime whose scheduler coordinates all this.
  • Compiles to native code, producing easy-to-deploy binaries on all the major platforms.
  • Garbage collection that doesn’t require knob-tweaking (optimized for low latency).
  • Statically typed, but has type inference to avoid a lot of “type stuttering”.
  • Great documentation that is succinct and includes many runnable examples.
  • Excellent tooling. Just type go build to build your project, go test to find and run your tests, etc. There’s CPU and memory profiling, code coverage, and cross compilation – all without external tooling.
  • Fast compile times. The language was designed from day one with fast compile times in mind. In fact, co-creator Rob Pike jokes that “Go was conceived while waiting for a big [C++] compilation.”
  • Very stable language and library, with a strict compatibility promise that all Go 1 programs will run unchanged on later versions of Go 1.x.
  • Desired. According to StackOverflow’s 2019 survey, it’s the third most wanted programming language, so it’s easy to hire developers who want to use it.
  • Heavily used in cloud tools. Docker and Kubernetes are written in Go, and Dropbox, Digital Ocean, Cloudflare, and many other companies use it extensively.

#go #developer

An Introduction to Go for non-Go Developers
5.35 GEEK