4 tips for learning Golang

4 tips for learning Golang

Arriving in Golang land: A senior developer's journey.

Man at laptop on a mountain
Image credits : 
x

Get the newsletter

Join the 85,000 open source advocates who receive our giveaway alerts and article roundups.

In the summer of 2014...

IBM: "We need you to go figure out this Docker thing."
Me: "OK."
IBM: "Start contributing and just get involved."
Me: "OK." (internal voice): "This is written in Go. What's that?" (Googles) "Oh, a programming language. I've learned a few of those in my career. Can't be that hard."

My university's freshman programming class was taught using VAX assembler. In data structures class, we used Pascal—loaded via diskette on tired, old PCs in the library's computer center. In one upper-level course, I had a professor that loved to show all examples in ADA. I learned a bit of C via playing with various Unix utilities' source code on our Sun workstations. At IBM we used C—and some x86 assembler—for the OS/2 source code, and we heavily used C++'s object-oriented features for a joint project with Apple. I learned shell scripting soon after, starting with csh, but moving to Bash after finding Linux in the mid-'90s. I was thrust into learning m4 (arguably more of a macro-processor than a programming language) while working on the just-in-time (JIT) compiler in IBM's custom JVM code when porting it to Linux in the late '90s.

Fast-forward 20 years... I'd never been nervous about learning a new programming language. But Go felt different. I was going to contribute publicly, upstream on GitHub, visible to anyone interested enough to look! I didn't want to be the laughingstock, the Go newbie as a 40-something-year-old senior developer! We all know that programmer pride that doesn't like to get bruised, no matter your experience level.

My early investigations revealed that Go seemed more committed to its "idiomatic-ness" than some languages. It wasn't just about getting the code to compile; I needed to be able to write code "the Go way."

Now that I'm four years and several hundred pull requests into my personal Go journey, I don't claim to be an expert, but I do feel a lot more comfortable contributing and writing Go code than I did in 2014. So, how do you teach an old guy new tricks—or at least a new programming language? Here are four steps that were valuable in my own journey to Golang land.

1. Don't skip the fundamentals

While you might be able to get by with copying code and hunting and pecking your way through early learnings (who has time to read the manual?!?), Go has a very readable language spec that was clearly written to be read and understood, even if you don't have a master's in language or compiler theory. Given that Go made some unique decisions about the order of the parameter:type constructs and has interesting language features like channels and goroutines, it is important to get grounded in these new concepts. Reading this document alongside Effective Go, another great resource from the Golang creators, will give you a huge boost in readiness to use the language effectively and properly.

2. Learn from the best

There are many valuable resources for digging in and taking your Go knowledge to the next level. All the talks from any recent GopherCon can be found online, like this exhaustive list from GopherCon US in 2018. Talks range in expertise and skill level, but you can easily find something you didn't know about Go by watching the talks. Francesc Campoy created a Go programming video series called JustForFunc that has an ever-increasing number of episodes to expand your Go knowledge and understanding. A quick search on "Golang" reveals many other video and online resources for those who want to learn more.

Want to look at code? Many of the most popular cloud-native projects on GitHub are written in Go: Docker/Moby, Kubernetes, Istio, containerd, CoreDNS, and many others. Language purists might rate some projects better than others regarding idiomatic-ness, but these are all good starting points to see how large codebases are using Go in highly active projects.

3. Use good language tools

You will learn quickly about the value of gofmt. One of the beautiful aspects of Go is that there is no arguing about code formatting guidelines per project—gofmt is built into the language runtime, and it formats Go code according to a set of stable, well-understood language rules. I don't know of any Golang-based project that doesn't insist on checking with gofmt for pull requests as part of continuous integration.

Beyond the wide, valuable array of useful tools built directly into the runtime/SDK, I strongly recommend using an editor or IDE with good Golang support features. Since I find myself much more often at a command line, I rely on Vim plus the great vim-go plugin. I also like what Microsoft has offered with VS Code, especially with its Go language plugins.

Looking for a debugger? The Delve project has been improving and maturing and is a strong contender for doing gdb-like debugging on Go binaries.

4. Jump in and write some Go!

You'll never get better at writing Go unless you start trying. Find a project that has some "help needed" issues flagged and make a contribution. If you are already using an open source project written in Go, find out if there are some bugs that have beginner-level solutions and make your first pull request. As with most things in life, the only real way to improve is through practice, so get going.

And, as it turns out, apparently you can teach an old senior developer new tricks—or languages at least.

About the author

Phil Estes - Phil is a Distinguished Engineer & CTO, Container and Linux OS Architecture Strategy for the IBM Watson and Cloud Platform division. Phil is currently an OSS maintainer in the Docker (now Moby) engine project, the CNCF containerd project, and is a member of both the Open Container Initiative (OCI) Technical Oversight Board and the Moby Technical Steering Committee. Phil is a long-standing member of the Docker Captains program and has enjoyed a long relationship with key open source...