The Go programming language (also known as Golang) is Google’s general-purpose programming language engineered for the multi-core reality of today’s computers. Go is a statically typed, compiled language like C++ that boasts the user friendliness of dynamically typed, interpreted languages like Python. Concurrent, garbage-collected, and designed for scale, Go is a programming language made for building large-scale, complex software.
Whether you’re in the camp that believes Moore’s Law is dead, or you think the law still has a fighting chance, the reality is we live in a world where the practical clock speed of a single core processor hasn’t changed much since Intel’s Pentium 4 processor reached 3.0 GHz back in 2004. Achieving higher performance in today’s devices requires multicore-architectures that are very different from the machines that were around when popular programming languages such as C++ and Java first appeared in the 80’s and 90’s. It’s one of the reasons today’s flagship 2018 MacBook Pro 13 can get away with a base clock speed of 2.7 GHz—it’s running an Intel® Core™ i7-8559U processor with four cores and eight threads.
And so it was that in late 2007, developers at Google conceived of Go: a language engineered for the multicore processors, cloud services, computation clusters, and networked systems that make up the computing landscape of modern IT infrastructure. Google’s main issues were programmer productivity and scale—managing the countless lines of software written in multiple languages such as C++, Python, and Java, across millions of machines handled as independent, networked compute clusters. If you’re looking for a programming language built for solving problems encountered in complex software infrastructure environments as you scale, Go is the performant systems language for you.
Go’s core feature set
Before we dive into the specifics, here’s a broad overview of the major features this language has to offer:
- Compiled. Go generates binaries for your applications complete with all dependencies. No interpreters or runtime installations required.
- Garbage collection. Go sports low-latency garbage collector for automatic memory management that is both efficient and concurrent.
- Safe. Go is a statically typed language that supports type safety; errors are caught by the compiler before execution.
- C-inspired syntax. Go’s syntax is reminiscent of the C family, but simplified with only 25 keywords, the ability to parse without type information/symbol tables, and a Pascal-like declaration scheme.
- Multi-paradigm. Go supports multiple programming paradigms including imperative, object-oriented programming (OOP) without inheritance, and functional programming.
- Standard library. Go has a powerful standard library of packages to support the development of Go programs.
- Simplified documentation. GoDoc is a static code analysis tool that creates simplified standardized documentation directly from your code.
- Concurrent. Go treats concurrency as a first class citizen—we’ll dive into more detail in the next section.
Goroutines and channels: concurrency for a multicore world
Concurrency is the ability to deal with lots of things at once, such as a web server handling multiple requests. Concurrency is especially useful for building software that can take full performance advantage of multiple cores or process threads. One of Go’s biggest selling points is that it supports two features that make concurrency easy out of the box: goroutines and channels.
Goroutines are functions that can run concurrently with others methods and functions. In contrast with parallelism, where functions can execute simultaneously, concurrency simply means that a program does not need to wait for a function to complete in order to move on to the next task. While parallelism is certainly possible, it is not the goal. Concurrency is about structure.
沙巴体育足球开户If you’re familiar with threads in Java, goroutines are lighter and easier to create. Goroutines are:
- Fast: quicker startup times than conventional threads
- Lightweight: only a few kBs in stack size, allowing you to run millions
- Flexible: growable, segmented stacks that only consume memory as required
- Easy-to-control: channels let two or more goroutines coordinate and synchronize their execution
沙巴体育足球开户Invoked with the “go” keyword, these functions will start and continue to run while the program moves on to the next statement in your code, without having to wait for the goroutine to finish. In a nutshell, Go lets you make the most of your hardware, by making it easy to design programs that can run concurrently across multiple cores. Checkout this video by Go co-creator Rob Pike for more detail on how to create high-performance software with Go’s concurrency patterns.
Composition over Inheritance
Sometimes you can tell a lot about a language by the features its creators choose to omit. Go deviates from most OOP languages by choosing composition over inheritance. Instead of subclasses and type-based inheritance, Go allows methods on any type via nifty constructs called interfaces. An interface is a set of methods: fixed behaviors that can be invoked as required. When a type implements its methods, the interface is implemented implicitly—no explicit declaration of intent required. Consider the standard library definition of the Hash interface:
沙巴体育足球开户Any type that satisfies the Hash interface above also implicitly satisfies the writer interface below:
Note that this is very different from class inheritance where a subclass depends on a parent class. Instead the focus is on the methods, one can simply write precise interface definitions and use them without having to lookup and tag them in every implementation. Since interface satisfaction is statically checked at compile time, everything remains type safe. Decoupling intent from definitions in this manner lets your software scale organically without having to worry about any predetermined hierarchies added at the start of your design. This is what Google means when they say Go is about composition not inheritance.
Built with Go
沙巴体育足球开户To give you some real world examples of how Go is being used in the world today, here are some examples of tools and software that use Go:
- Kubernetes, the Google-backed container management platform.
- ItsAbot, the build-your-own digital assistant framework.
- CloudFlare, a content delivery network, DDoS mitigation, and internet security service.
- Basecamp, the popular project management suite.
- Dropbox, the cloud storage and file sharing app.
- Malwarebytes, the antivirus software.
Go has been adopted to serve the server-side needs of a wide variety of companies and tools. Although most uses of Go at Google are confidential, you can bet that the company takes full advantage of the language they built.
Should I use Go for my next project?
Go was created to solve “Google-sized” problems. As a general purpose language that specializes in concurrency, Go is especially useful for projects that involve distributed networks, cloud services, and other complex back-end technologies沙巴体育足球开户. If your organization is running into common scalability issues such as slow builds, uncontrolled dependencies, costly updates, messy documentation, and difficulty writing automation tools, Go may be the programming language for you.