Advantages, disadvantages and musings
Go, also known as Golang, was first developed by three designers at Google way back in 2007. While it was introduced to the open source community in 2009, Go only really started gaining traction as a programming language in the past several years as notable companies and products like Dropbox, Docker, Google (of course), eBay, Baidu and Spotify have picked it up. Go is supported by Windows, Mac OS X, Linux, BSD, UNIX, and mobile devices via Android and iOS.
We had our first experience with Go at Coherent Solutions when a client purchased a new system that was implemented on Go. They had no expertise with Go in-house, and because we have demonstrated an ability to pick up new languages quickly, they asked for our help with it. Here are some things we have learned about it.
Unhappy with the complexity of C++, Go’s designers were looking to create a systems programming language that would be:
- An imperative, compiled, statically-typed language
- Scalable to large systems, like Java or C++
- Clean and light on keywords syntax
Type inheritance is intentionally absent from Go. Instead of introducing an embedding mechanism, programmers can embed type with a struct or interface. Go also supports the duck typing concept. There is no need to specify interfaces, which are supported by the type. So if a type contains interface methods, Go will implement this interface.
Advantages of Go
- Performance As a compiled language, Go is ten times faster than Python or Ruby. And although it is still a little bit slower than C++ or Java, Go still has plenty of opportunity to improve performance as its compilers mature.
- Development speed and ease Go was created to be easy-to-learn, with simplified syntax. It is much faster to create programs in Go than in C++ which requires manual memory management, for instance. Plus, Go’s standard library is rather comprehensive and covers all base scenarios. Beyond that, there are many third-party libraries. You can also use several popular IDE’s (IntelliJ IDEA, Eclipse IDE) with additional plugins to develop on Go.
- Concurrency It is easy to create asynchronous code using Go. There is a supporting list of synchronization mechanisms, including goroutines and channels. The goroutines concept is one of the greatest Go features. A goroutine is a lightweight, “green” thread that only requires several kilobytes of memory. You can easily create thousands of them. Channels are used to organize communication between goroutines.
- Garbage collection Unlike C++, but like Java or .NET, Go has automatic garbage collection which relieves developers of having to deal with memory deallocation. GC also decreases the probability of some categories of bugs. The 1.5 version of Go has a GC latency well below ten milliseconds.
- Static, strong typing With this you can detect and correct a lot of errors in the source code during compilation.
- Static linking Go runtime and all libraries are included in Go applications. This means less flexibility, but more durability. There is no need to worry about any dependencies when deploying Go applications.
- Cross platform Go supports cross compilation on most popular platforms.
- Open source
- Supports unit testing A built-in testing package provides support for automated testing.
Disadvantages of Go
- Small developer community As of now, the developer community is not as large as those for competitive technologies like Python, Ruby and Node.js.
- Lack of official support There is no official support from a resource-rich company or vendor.
- Lack of generics Developers of Go have noted that generics could be added in future versions. For now, there are work-arounds that allow you to emulate generics.
- Lack of exceptions This was intentional. Instead of an exception mechanism, you get error codes from functions.
Based on the pros and cons we have discovered with Go, it makes sense to use it in these kinds of applications:
- Performance-critical, scalable backend components
- High load websites or web services with simple business logic
- High-performance components for Android and, in the future, iOS
- Education – a good, easy introduction to learning a programming language
Go’s popularity has grown over the last several years, with many more companies trying it in a variety of interesting applications and services in 2015. According to a RedMonk rating, Go moved up from number 17 to number 15 in the first 7 months of 2015. This ranking is based on language popularity on GitHub and Stack Overflow. On the negative side, Go fell from number 46 to below 50 between December, 2014 and August, 2015 on the TIOBE rating. The difference is that TIOBE builds their ratings on search requests.
- Written in Go, Docker is used by eBay, Baidu, Yandex and Spotify. This platform runs distributed applications, isolated from each other. An application is packed into a Docker container with all its dependencies and executed by the Docker engine. Instead of requiring a separate virtual machine for each container, Docker uses Linux kernel isolation functionality, rendering containers lightweight and without any virtual machine overhead.Microsoft announced support of Docker containers in the next version of its Windows server and Microsoft Azure. IBM also announced a strategic partnership with Docker on their cloud and on premise solutions.
- Google has begun using Go for many projects, including its download server, dl.google.com.
- Dropbox migrated performance-critical backend components from Python to Go – about 200,000 lines of Go code.
- Yandex rewrote the server API of their browser from C++ and Python to Go.
- io is a cloud-based message queue service and multi-language platform that runs parallel tasks at a massive scale. Based on Docker, it is written in Go.
- Revel is a high-productive web framework for the Go language.
- Syncthing is an open-source file synchronization client/server application written in Go.