Why you should learn Go
- select the contributor at the end of the page -
As technology evolves, so does the number of new programming languages. Trends such as ubiquitous multi-processor devices, the explosion of mobile devices and the current IoT revolution have helped drive this explosion. But whatever the cause, developers are now living in an increasingly fragmented world. Still, it’s our job to keep up with the latest changes, and that includes one of the newer languages on the block, known as “Go.” Let’s take a look at what makes this one stand out from its counterparts, and why you should take the time to learn it.
What is Go?
Go was started by a small team at Google as an attempt to gracefully handle the challenges that large organizations (like Google) face. It’s a response to growing trends that seek to reduce the mental overhead that a programming language requires and to reduce compile times to support code-build-test loops required by methodologies such as Test-driven Development (TDD). Go emphasizes simplicity and clarity in its code so that it’s easier to understand and maintain. At the same time, Go incorporates powerful features that allow very sophisticated applications to be built.
What makes Go different?
For starters, it’s simple. As mentioned, one basic problem Go tries to solve is the need to reduce the mental overhead that it places on developers. Several aspects of the language highlight this. These include:
Many languages have numerous keywords that a developer must remember. Several of these keywords are designed to support programming concepts that have been around for decades. With Go, many of these concepts have been condensed as much as possible in order to reduce the amount of keywords required. As a result, Go currently has around 25 keywords, as opposed to 50 or more for languages like Java and C#.
Simple scoping rules
Many languages offer developers great flexibility to ensure that variables and functions can be hidden from other parts of the code base. Go has only three levels of scoping and very simple conventions for determining scope:
- Local variables (declared within a function) are scoped to the current block.
- Package level variables are scoped to the package if they start with a lower-case letter.
- Package level variables are publicly scoped if they start with an upper-case letter.
There’s no “private” scope, as you might have expected, which is enough to make some developers uncomfortable. But in practice, this actually opens up a lot of opportunities.
Built-in garbage collection
Garbage collection is a difficult problem to solve. However, manual memory management often incurs a fairly high cost on the developer and makes it more difficult to write error-free code. This is why the developers of Go made it a requirement to have it in the language. Initially, the garbage collector could take a heavy toll on an application in terms of performance. However, the cost of garbage collection is falling rapidly thanks to determined effort.
Concurrent execution is a challenge that every modern application must manage in order to take advantage of today’s multi-processor computing environments. Go adopted the Communicating Sequential Process (CSP) model (aka the Actor Model) that’s been used successfully by Erlang. Go combines light-weight green threads (called goroutines) with communication pipelines called channels to form a simple, powerful concurrency model. This allows an application to run with thousands of actors, without the burden of trying to keep shared memory free from corruption.
To create modern applications, you need more than just a great language. Modern applications rely on testing to ensure correctness, documentation generators to communicate how the application works, and linters to ensure that coding standards are adhered to. Go embraces each of these issues as core concerns of the language, not simply an add-on to be dealt with by another team. As a result, installing the Go development tools provides instant access to all of these capabilities and a guarantee that they’ll work together without having to fight just to get everything working.
While Go succeeds on most fronts in its effort to be both powerful and simple to use, it has one thing in common with all other languages: It isn’t perfect.
You’ll find a basic package manager built into Go, however, if you’re used to working with first-class versions like Ruby’s or Node’s, you’ll notice some gaps. Go’s package manager covers the basics, but it doesn’t support things like version pinning, which can be critical when your application depends on a specific version of a library. The community is working on it with tools like godep, but it’s not a core concern yet. With the release of version 1.5, the Go core team is starting to improve the tooling, but a final solution is still in the distance.
When Go first launched, it used the GNU debugger (GDB) as its primary source of debugging support. While this works in limited scenarios, Go’s execution model is so different from what GDB expects that it quickly runs into issues. Once again, the community is working on it with projects like delve, but you won’t find any deep integration of a debugger in an IDE right now.
While it’s still in its early stage, there are many benefits to learning Go. You might hate it or you might fall in love with it, but it will almost certainly make you to think differently about programming. Development with Go is different than other languages I’ve worked with; instead of pulling in dozens of libraries and learning each, Go asks that you learn just a few concepts and then focus on applying those concepts to your problem.