Why should you spend time learning go ?
The language is great
- Simple: Languages syntax is quite small and easy to learn. Complex features that other languages provide have been omitted: inheritance, generics and pointer arithmetic.
- Elegant: No semicolons. The scope of variables has been thoughtfully designed, it’s a huge win for readability of code. I personally add (often useless) brackets in my C to make it more readable. The
deferkeyword allows some clean and simple resource freeing.
- Easy to use: Having a garbage collector makes it easy to use.
- Built for concurrency: Making concurrent code has never been so easy. All IO calls are blocking but in a go-routine kind of way, meaning that as soon an I/O or time operation occurs, the current running thread will execute an other go-routime. It’s the java’s Future mechanism made easy.
- Comes batteries included: Like python, it has some great standard packages.
- Go on C libs: cgo makes it simple to integrate C code and C libraries. But for all the I/O related task, go internal code will perform much better (it shares a threads).
- Unicode support: It’s one thing you won’t have to worry about.
But it’s not just the language
It is given a complete environment. You can can type “
build: Builds your code. No use for a Makefile or complex stuff like that. “go build” takes care of everything.
run: Runs your code if you don’t want to build it.
test: Alows some very easy (and fast) unit testing of your code.
get: Fetches any kind of package.
fmt: Formats your code. You don’t have to define some code formatting rules. Your code is reformated following the go requirements.
doc: Documents your code. No doxygen or javadoc, go has it.
vet: It inspects your code to help you detect wrong behaviors.
fix: Fixes your code by replacing old APIs calls by new ones.
install: Installs your packages (libraries). Installing a package on a host is easy as hell.
tool: Contains a set of useful tools. Most important one in my opinion is the pprof CPU/memory profiler.
To be exhaustive, I’d like to mention few issues you can expect from this languages at this stage.
- Huge binaries: Mostly because produced go binaries are almost completely static but not only, they are huge (like 2MB big hello world). The problem is known and likely to be reduced in the future.
- No big GUI libraries: The language is still young (Go 1.0 was released in Mars 2012) and focus has been put on server side code. So there’s not much librairies or librairies environment built out there.
- No real localization: In python, we usually use
_('stuff')but here we don’t. In Go you have solutions, but none of them is provided by the standard packages at this stage.
- You might be disturbed by Go’s interfaces: If you come from java with its interfaces inheritances and its powerful namespaces. You might be disturbed that some interfaces included other interfaces because they include their functions.
- Depencies are not versionned. When you use imports within your code, it might not work in a few months. Also there are ways around it. Coming from java’s maven or gradle, it’s quite disturbing.
Can we bet on it ?
Is it matture enough ? Is is a real disruption ? Will the language actually take-off ?
It’s definitely a major evolution. Because you have many good and exclusive feature while sill having some good old C language bindings and a LOT of libraries have already been ported or binded on it. The
"go get" command is also a great recipe for boosting community support.
If (or when should I say) you are hooked, read the effective go page. There are many things like the getter/setter conventions that you will only see here or in the thousands of open-source Go projects outhere.
Just as a quick note: It’s static language. If you come from PHP, ruby or python with little C/C++/java experience, you might find the variable scoping a little bit hard to understand at first.
- On Go’s Web Application Ecosystem: A good summary of your options when you start a web app in go.
- Go: Code that grows with grace
: An introduction to what is go
- From python to go: this and that
- 2 years of Go at IronMQ
I’ll try to update this page later.