I recently started learning Go. I haven’t properly learned a new language in a while, and Go seemed like a nice complement to my usual go-to language of Python. I’m going to try to stay clear of the low-level details in this post, and instead focus on my experience of learning and using the language.
I did consider looking at Rust, which is a fantastically interesting language, but the syntax is changing too fast at the moment for me to consider it to be a practical choice. Having said that, I am going to have to have a look at it some time in the future.
A friend of mine, James Doig struggles to understand why I picked Go - I think the argument was “Why do Python programmers seem to like Go so much? Python’s syntax is so nice - Go makes me want to claw out my eyes!”
Having now worked on some small, yet not-toy examples, I do know where he’s coming from - Go syntax is a bit ugly in my opinion. Purposefully-missing constructs, such as classes, inheritance and exceptions are jarring at first. Random bits of syntax, such as switching on type, are definitely eye-bleed inducing:
1 2 3 4 5 6
Seriously, what is going on in that first line? I’m hoping at some point that I will reach enlightenment and see some sort of inherent beauty and consistency to it, but that hasn’t happened so far.
The flipside to this is that Go is actually a very pragmatic language. Internally, I compare it more to C than Python. The language is small, fast, typesafe, and concurrent. It also deals nicely with Unicode, which is tacked on to C.
I highly recommend reading Go at Google: Language Design in the Service of Software Engineering which explains the problems the language and language tool designers were trying to solve. Some of them are not immediately obvious.
Go only supports static linking, so your application will be distributed as a stand-alone binary. Because of this, Go has significantly reduced the dependency-management problem from deployment. I’m now very keen to deploy my first Go server as a 12-factor app.
How to learn Go
The first thing I did was to go through the interactive tour on the Golang website, which is good for a taste of the language, but doesn’t really leave you with the knowledge to properly write your own applications.
Other documentation on the website is extremely useful and well-written - I tend to keep Effective Go open in a tab because it serves as both a good reference, and a good guide for writing idiomatic Go. I moved from these to the free e-book An Introduction to Programming in Go, which is great, but unfinished. I found the exercises in each chapter to be fantastically useful in taking me from “I think I understand this language” to actually being able to solve coding problems in Go.
My current project is actually a rewrite of one of FanDuel’s smaller internal services - one which I feel I understand well enough to reproduce in Go. There’s been a certain amount of yak-shaving, as our internal protocol is JSON-RPC2, and Go only supports JSON-RPC1 (out of the box!) On a production project this might have been annoying, but given that my goal was to improve my knowledge of Go, upgrading the existing library to the newer protocol has been a useful experience.
Awesome Go is also a great way to find out about frameworks and libraries that may make life easier.
I’m not saying these are the only resources for learning Go, but these have helped me to get to the point where I feel my lack of knowledge of Go is not constantly holding me back.
I like Go a lot. The documentation that comes with it is excellent, and so far some of the language limitations have not held me back at all. Although I say that I think of Go as a ‘new C’, really it doesn’t feel like that to code. It does in fact feel like coding in a subset of Python - despite Go being statically typed. I could get used to this inferred typing!
I haven’t built any production code yet in Go, but I’m starting to want to. I highly recommend if you are looking for a faster, lower-level version of Python or Ruby that you check it out.