Technical Article => Programming => Go

GoLang is a strong typed language which means it is less flexible than interpreted languages by nature. But Go provides Any type(interface) and Reflect mechanism which make the language very close to interpreted languages on flexibility. More and more people start to learn GoLang.

This post is mainly for listing down some of the advantages and disadvantages of GoLang.

Advantages

Performance(Machine code)

GoLang is a compilation language which can be compiled to machine code and the compiled binary can be directly deployed to target machine without extra dependency. The performance is better than those interpreted languages.

Dynamic language feel

GoLang is a static language but it gives a feeling of dynamic language to developers. As a static language, lots of hidden issues can be detected when doing the compilation, especially syntax errors. Also there are lots of packages available for developer to use and it's very easy to import them during development, this makes us less worried about its capability and makes us feel like we are dealing with a dynamic language.

Concurrency support

This is probably the most praised feature of GoLang. It supports concurrency since it's born. It can fully utilize multi core capability. GoLang uses goroutine to achieve concurrency and it provides a very elegant goroutine scheduler system which makes it easy to spawn millions of goroutines. The stack usage can dynamically expand/shrink as well which makes the memory usage more smart. This is different from Java thread which normally allows only thousands of threads to be created. For more comparison, please check out Russell Cohen's article Why you can have millions of Goroutines but only thousands of Java Threads.

Built in runtime with GC support

Though its GC is not perfect, it can fulfill most of requirements about garbage collection. For detailed explaination about GoLang GC, check out Getting to Go: The Journey of Go's Garbage Collector.

Easy to learn

GoLang's authors all have C background, GoLang comes with gene of C. There are 25 keywords but with abundant expression power. It can support almost all features seen in other languages such as inheritance, overloading, object etc.

Tool chain

There are lots of easy to use built-in tools which help developers write maintainable and readable code. Efficiency is largely improved. These include gofmt, goimport etc. They can make our code look standardized and ease the work of review a lot.

Native C support

You can embed C code in a Go program so that you can use lots of powerful C libraries.

Disadvantages

Lack of frameworks

There is no major framework for GoLang developers. There is in other languages though. Ruby has Ruby on Rails, Python has Django and PHP has Laravel.

Error handling

Go programs requires function to return error if there might be error expected. This may cause problem where the track of the error is lost which leads to missing useful error handling logic. There are tools which can help detect this kind of miss such as errcheck and megacheck. But they are more like workarounds. Also developers need to write lots of if blocks to check error and handle it which makes the code less clean.

Package management

Package management in Go is not perfect, neither. By default, it cannot create a dependency tree with fixed package version, this means the build created may be based on different version of packages when building at different time. In contrast, Python, NodeJS(npm) and Ruby all have relative well maintained package management system. For example, in a Ruby on Rails project, you can have a Gemfile file which defines the dependencies and their dependent versions which means the same version of package would be used to create a new build even in the future some of them have later updates.

There are other advantages and disadvantages of GoLang, let embrace them and deal with them smartly.