After working for ages in PHP, Python and Java, I wanted to try something new. I was (and still am) happy with those languages, but it just didn’t feel right, there was something missing. Just like everything in this world, each and every language has its own pluses and minuses. Some of the pluses and minuses are just facts, while some are just subjective feelings toward the language.
For example, I just adore Python for its simplicity and ability to create new things in matter of “minutes”. But unfortunately it’s interpreted language, and that makes it a little bit slow (I am not taking PyPy or CPython into this story), which implies for all interpreted languages.
Then I heard for Go…and I felt the same excitement I felt years ago when I started learning Python. I felt the same emotion of happiness.
Why I fell in love with Go
There are few reasons why. Some of them are facts, while some of them are subjective feelings :). There are plenty of more reasons, but I’ll name a few.
It’s mixture of Python and C
It’s simple as Python and strong as C. Of course it’s slower than C, but it really doesn’t matter (unless you are programming for a spaceship or a car breaking system). Since it’s very minimalistic, development time is decreased a lot, yet the final product is fast!
It forces you to write good code
Let me elaborate on this a bit. Everything in Go resolves around Interfaces. If you want to write good code, you certainly will use Interfaces. That way it’s much more easier to test and write your code. There is no awkward mocking of “classes” (structs). You also don’t depend on the implementation. You can overdo it with Interfaces, but it’s better to overdo it, then to depend on implementation. Writers of the language wrote this awesome page called Effective go. By reading it and trying to implement it, your code will become more idiomatic, and much much more effective ;). If you don’t read effective go and you don’t understand it and implement it, then…well, you are screwed :). Don’t fight it. Embrace it.
It’s compiled and everything is linked
You can compile it for every Operative System and for every architecture there is. Maybe not all of them, but most commercial ones like: OS(X), Windows, Linux, FreeBSD, OpenBSD,.. And the best thing is, you can do cross-platform compilation. For example, you can compile application for Windows OS (.exe) on a Linux OS. That being said, I can compile something on my Mac and push it directly on production Linux server. Server doesn’t need to have any dependencies or libraries preinstalled. Simple Alpine will do. Compile time is incredibly fast!
It comes with a lot of tools to help you
I am talking about gofmt
which will format your code in an already defined standard. Because of that, it’s very team friendly. That way, each Golang developer can switch from one project to another and not worry about code style and code formatting. There are plenty of other tools which can help you and your team.
Concurrency!
To simplify, you are able to run your code in concurrent manners and you don’t have to worry about it. Just put keyword go
before running things in parallel.
Of course you have to worry about it, but the need for mutexes and locks is minimal.
Garbage collected
If you are worried about garbage collection, there is a quote from Golang’s site:
A careful programmer can reduce the garbage collection overhead dramatically by using the language well.
Of course I have to show both sides of the Golang
Like every good article, I must show both sides of the story. To me, Golang is the future of programming, but there are some things that get in the way. And that is…you guessed it…GOPATH variable, workspaces setup, the need to name project’s folder structure as repositories paths (github.com/example/repository
).
What I learned from it, even though I don’t approve it and don’t like it, is don’t fight it. You can fight it, but don’t. You are going to lose. Go with the flow and accept your destiny.
Also, forget everything you know from Java, PHP, Python,…and don’t try to implement it in Go. With Go everything tries to be simple. There isn’t any space for UserFactoryDecorator
and similar types in Go.
After all
There are some downsides to Golang, but it’s nothing compared to all good things of the language. To put it in the perspective, it’s like having a car of your dreams with a little scratch on the radio. You know it’s there, but you don’t care, since it’s your dream programming language…I mean a car :).