Go (Language)

Gopher, Go's mascot. Source: Dudeja 2017.
Gopher, Go's mascot. Source: Dudeja 2017.

Go is an open source, compiled, concurrent, garbage-collected, statically typed language developed at Google. Google created it to solve its own problems in relation to multicore processors, networked systems and large codebases.

While languages such as C and C++ are fast, they are hard to master and development takes longer. While Python is easier to work with, it compromises on runtime efficiency. Go was designed to be efficient, scalable and productive.

Discussion

  • Why was Go invented when there were already many popular languages?
    Go balances ease of programming, efficiency and concurrency support. Source: Patel 2017.
    Go balances ease of programming, efficiency and concurrency support. Source: Patel 2017.

    Go was invented (in 2007) at a time when multicore CPU architectures were common, largely because Moore's Law was failing to deliver. With multiple cores, code can run in parallel on all available cores; but there was no programming language that simplified the development of multithreaded applications. The responsibility of managing different threads safely and efficiently fell on developers. Thread-locking, race conditions and deadlocks are usual challenges. Go was designed with concurrent programming in mind.

    Golang FAQ states that in the days before Go,

    One had to choose either efficient compilation, efficient execution, or ease of programming; all three were not available in the same mainstream language.

    Go balances these different expectations of a programming language. Go was really designed to solve problems Google faced with large software systems. Hence, it was less about research into language design and more about software engineering to solve problems at hand. Some of the problems Google faced were slow builds, uncontrolled dependencies, poor code readability, challenges with automation tools and cross-language builds.

  • What are the main features of Go language?
    Main features of Go. Source: Qwentic 2018a.
    Main features of Go. Source: Qwentic 2018a.

    Go's main features include concurrency, scalability, error checking, fast performance, garbage collection and cross platform. It's fast because it's a compiled language and not an interpreted one like JavaScript. Garbage collection pauses have been reduced to about 100 microseconds. Go's built-in error type enables developers to spot errors early. It's designed for the cloud and can run on various platforms.

    Because Go has types and methods, we can call it an object-oriented language. But there's no type inheritance. Instead, Go uses interfaces.

    Go achieves concurrency using goroutines, which are then mapped to operating system threads. If a thread is blocked, goroutines can be moved to another thread. Goroutines are therefore cheap, requiring nothing more than stack memory. Built-in channels are used to communicate between goroutines.

    Go is opinionated and focused on its design goals. Therefore, what it leaves out of the language are just as important. Go doesn't have generic types, exceptions and assertions.

    Other features mentioned elsewhere are godoc for documentation; gofmt for code formatting; golint for linting; built-in testing and profiling framework; race condition detection.

  • What sort of applications can benefit from using Go language?

    If you're into systems programming with support for multithreading, Go is a suitable language. Go can be used for building any server-side app containing thousands of communicating threads.

    Due to its roots in Google, Go is suited for large distributed projects involving multiple teams. It's taken off in the cloud infrastructure space, platform automation, tooling apps and DevOps pipelines. Go's static binaries without external dependencies are easier to manage. Cross-platform CLI tools can be created. Because Go compiles to native code, performance-critical apps can benefit from it. As Go's Garbage Collection (GC) matures, it can suit embedded systems.

    While Go was originally for systems programming, it's been adopted for microservices. This is due to its "elegant concurrency model, simple binary deployments, low number of external dependencies, fast performance, and runtime efficiency." There's also an expectation (back in 2015) that Go will grow into a general-purpose programming language and be adopted for GUI apps, IoT apps, web/mobile apps, robotics frameworks, and more. It's suited for data science work.

    Alternatively, it's been said that Go is not suitable for GUI apps, kernels, drivers or embedded systems.

  • How's the adoption of Go language?

    Back in 2014, it was reported that many open source projects have adopted Go: Docker, Kubernetes, Weave, Shipyard, etcd, Fleet, Deis, Flynn. Since Go is suited to distributed server apps, all of these apps are cloud related. Lime is an example of a desktop app for text editing. InfluxDB, a distributed time series database, is written in Go. Gogs (Go Git Service) helps you to run a Git service, like GitHub. Go is a suitable fit for Docker due to static compilation and ability to build for different architecture with less effort.

    Among the big names using Go are Uber, BBC, Novartis, Soundcloud and Basecamp. Uber has reported better throughput, latency and uptime. BBC uses it for backend, including crawlers and web scrapers. Soundcloud's build and deployment system is in Go.

    In 2016, Go was rated the most popular language in the TIOBE index. Multiple developer surveys in 2018 show interest and adoption of Go. In StackOverflow's survey, Go is in the top five most loved/wanted languages. Community contribution to Go is growing steadily.

    There's also a curated list of companies worldwide using Go.

  • What are some criticisms of Go language?

    Go doesn't support generics, which means that code written for one data type can't be reused for another. Interfaces are implicit. Sometimes it's hard to tell if a struct type implements an interface. Library support for Go from vendors is lacking. While Go is open source, key maintainers are seen to be non-receptive to suggestions from the community. Packages are not versioned in a centralized place.

    We can't define immutable data types. Complex data types are not available out of the box: hash, tree, set. Go doesn't support overloading. Compile-time checks are lacking. It's slow compared to C, C++ and Rust. It's been said that Rust succeeds in areas where Go fails. There's also a curated list of Go criticisms.

    From Go's perspective, some missing features are actually by design, reflecting Go's simplicity. Generics come with a higher complexity. Without exceptions, developers are forced to do explicit error checking. Overloading makes problems harder to debug. Being minimal and opinionated means that everyone writes code the same way: there are no debates about using tabs versus spaces or for versus while.

  • For a beginner, what online resources can you recommend to learn Go programming?
    Learn Go in 12 Minutes. Source: Wright 2018.

    Golang's official FAQ page is a good place to start. Other resources include the Go official documentation and the Go Wiki pages.

    A curated list of Go frameworks and software is available on GitHub. There's also a curated list of 18 Go experts to follow. For latest news, the official Go blog and Golang Weekly newsletter are useful. For conferences, there's GopherCon and the European dotGo.

Milestones

Sep
2007
First design notes for Go. Source: Griesemer 2015, slide 8.
First design notes for Go. Source: Griesemer 2015, slide 8.

Three engineers at Google (Robert Griesemer, Rob Pike and Ken Thompson) invent Go. Their aim is to design a better language for Google's workflows. In particular, they notice lack of concurrency support in current languages and long build times. They want a small, compiled language with modern features.

Nov
2009

Go is made open source.

Mar
2012

A major release named Go 1 is released. It's stated that language will be stable and compatible with future updates of Go 1.

2014

World's first Go conference, GopherCon, is organized in Denver, USA. About 700 gophers (Go developers) attend the event.

Jan
2017

As a dependency management tool for Go packages, dep is released. Developers adopt this in preference to many community-led tools. Dep uses semantic versioning plus a configuration file that specifies dependencies. Version 0.1.0 of dep becomes available on GitHub in May 2017.

Jul
2017

At GopherCon 2017, Russ Cox presents initial ideas for Go 2 with a goal "to fix the most significant ways Go fails to scale." He outlines the community process through which Go 2 will be defined. Early draft designs of Go 2 consider error values, error handling, and generic programming. As of November 2018, Go 2 is still under development.

Aug
2018

Version Go 1.11 is released. Two major versions are supported at any point in time. This means that versions 1.11 and 1.10 will be supported until version 1.12 appears.

Sample Code

  • // Simple Hello World example
    // Source: https://golang.org/
    package main
     
    import "fmt"
     
    func main() {
    	fmt.Println("Hello, 世界")
    }
     
     
    // Concurrent Prime Sieve example
    // Source: https://golang.org/
    package main
     
    import "fmt"
     
    // Send the sequence 2, 3, 4, ... to channel 'ch'.
    func Generate(ch chan<- int) {
    	for i := 2; ; i++ {
    		ch <- i // Send 'i' to channel 'ch'.
    	}
    }
     
    // Copy the values from channel 'in' to channel 'out',
    // removing those divisible by 'prime'.
    func Filter(in <-chan int, out chan<- int, prime int) {
    	for {
    		i := <-in // Receive value from 'in'.
    		if i%prime != 0 {
    			out <- i // Send 'i' to 'out'.
    		}
    	}
    }
     
    // The prime sieve: Daisy-chain Filter processes.
    func main() {
    	ch := make(chan int) // Create a new channel.
    	go Generate(ch)      // Launch Generate goroutine.
    	for i := 0; i < 10; i++ {
    		prime := <-ch
    		fmt.Println(prime)
    		ch1 := make(chan int)
    		go Filter(ch, ch1, prime)
    		ch = ch1
    	}
    }
     

References

  1. Adrian, BG. 2018. "Golang, it was love at first sight." dev.to, September 18. Accessed 2018-12-05.
  2. Bate, Steve. 2014. "Go is boring." October 16. Accessed 2018-12-04.
  3. Blue Matador. 2017. "Mini Guide to Google's Golang and Why It's Perfect for DevOps." Blog, Blue Matador, April 18. Accessed 2018-12-04.
  4. Bugfender. 2017. "Should I Go? The Pros and Cons of Using Go Programming Language." dev.to, May 23. Accessed 2018-12-05.
  5. Cox, Russ. 2017. "Toward Go 2." The Go Blog, July 13. Accessed 2018-12-09.
  6. Dudeja, Kanishk. 2017. "The beauty of Go." Hacker Noon, October 06. Accessed 2018-12-04.
  7. Francia, Steve. 2018. "Nine years of Go." The Go Blog, November 10. Accessed 2018-12-04.
  8. Gaule, David. 2017. "18 Golang Experts to Follow Online." Blog, New Relic, February 16. Accessed 2018-12-04.
  9. Gerrand, Andrew. 2014. "GopherCon 2014 Wrap Up." The Go Blog, May 28. Accessed 2018-12-09.
  10. Golang Dep. 2018. "golang/dep." Golang, GitHub, October 04. Accessed 2018-12-10.
  11. Golang Doc. 2018a. "Release History." Build version go1.11.2. Accessed 2018-12-04.
  12. Golang Doc. 2018b. "Frequently Asked Questions (FAQ)." Build version go1.11.2. Accessed 2018-12-04.
  13. Griesemer, Robert. 2015. "The Evolution of Go." GopherCon 2015 Keynote, July 09. Accessed 2018-12-04.
  14. Griesemer, Robert. 2018. "Go 2, here we come!" The Go Blog, November 28. Accessed 2018-12-09.
  15. Griesemer, Robert, Rob Pike, Ken Thompson, Ian Taylor, Russ Cox, Jini Kim and Adam Langley. 2009. "Hey! Ho! Let's Go!" Blog, Google Open Source, November 10. Accessed 2018-12-09.
  16. Hosu, George. 2018. "The success of Go heralds that of Rust." Medium, October 13. Accessed 2018-12-04.
  17. Jones, Samuel. 2018. "The pros and cons of programming in Go." WillowTree, March 2. Accessed 2018-12-05.
  18. Patel, Keval. 2017. "Why should you learn Go?" Medium, January 08. Accessed 2018-12-04.
  19. Pike, Rob. 2012. "Go at Google: Language Design in the Service of Software Engineering." Adapted from SPLASH 2012 Keynote. Accessed 2018-12-09.
  20. Qwentic. 2018. "Companies Using Golang." Blog, Qwentic, January 17. Accessed 2018-12-04.
  21. Qwentic. 2018a. "Why Golang?" Qwentic Consulting, on Google+, July 06. Accessed 2018-12-09.
  22. Qwentic. 2018b. "Why Golang?" Qwentic Consulting. Accessed 2018-12-09.
  23. Rogovoy, Kirill. 2018. "Here are some amazing advantages of Go that you don't hear much about." freeCodeCamp, February 01. Accessed 2018-12-04.
  24. Rouse, Jeff. 2017. "Why Go is skyrocketing in popularity." Opensource, November 02. Accessed 2018-12-04.
  25. Talim, Satish Manohar. 2015. "Type of applications being developed in Go?" Medium, September 10. Accessed 2018-12-04.
  26. Wallez, Sylvain. 2018. "Go: the Good, the Bad and the Ugly." April 10. Accessed 2018-12-04.
  27. Wright, Jake. 2018. "Learn Go in 12 Minutes." YouTube, January 28. Accessed 2018-12-09.
  28. Yegulalp, Serdar. 2014. "10 open source projects proving the power of Go." InfoWorld, November 11. Accessed 2018-12-05.

Further Reading

  1. Pike, Rob. 2012. "Go at Google: Language Design in the Service of Software Engineering." Adapted from SPLASH 2012 Keynote. Accessed 2018-12-09.
  2. Pike, Rob. 2014. "Hello, Gophers!" Gophercon Opening Keynote, April 24. Accessed 2018-12-09.
  3. Patel, Keval. 2017. "Why should you learn Go?" Medium, January 08. Accessed 2018-12-04.
  4. Wallez, Sylvain. 2018. "Go: the Good, the Bad and the Ugly." April 10. Accessed 2018-12-04.
  5. Bayburtsyan, Tigran. 2017. "5 Reasons Why We switched from Python To Go." Hacker Noon, March 31. Accessed 2018-12-04.
  6. Quintana, Gerald. 2017. "From Java to Go." January 15. Accessed 2018-12-04.

Article Stats

Author-wise Stats for Article Edits

Author
No. of Edits
No. of Chats
DevCoins
3
0
1237
2
1
10
1
0
7
1367
Words
1
Likes
7587
Hits

Cite As

Devopedia. 2022. "Go (Language)." Version 6, February 15. Accessed 2023-11-12. https://devopedia.org/go-language
Contributed by
3 authors


Last updated on
2022-02-15 11:52:13
  • Golang Data Types
  • Concurrency in Go
  • Golang Unit Testing
  • Golang Patterns
  • Golang Web Frameworks
  • Dependency Management for Golang