Switching from Python to Go? Here's What You Need To Know

Continued from page 1. 

This is an asset of Go because frequently the nature of Python results in code that other developers find difficult to understand when reading their peers' work. With Go, developers can easily read each other's code and quickly understand the context (although code readability is no substitute for great inline Documentation).

Concurrency and Channels

Go is a language that keeps things simple. It does not introduce many new concepts, and its focus is on creating a simple language that's easy to work with and super fast.

Go does become innovative in its goroutines and channels. Goroutines are Go's lightweight approach to threading; channels are the preferred way to communicate between goroutines.

Goroutines are inexpensive to create and require only a few KBs of additional memory. Because they're very light, teams may have up to thousands of them running at the same time.

You use channels to communicate between goroutines. The Go runtime handles the complexity. Go's goroutines and channel-based approach to concurrency makes using all available CPU cores and handling concurrent IO easy, all without complicating development. Compared to Python and Java, running a Function on a goroutine requires minimal boilerplate code. Instead, teams prepend the function call with the keyword "go":

package main

import (
    "fmt"
    "time"
)

func say(s string) {
    for i := 0; i < 5; i++ {
        time.Sleep(100 * time.Millisecond)
        fmt.Println(s)
    }
}

func main() {
    go say("world")
    say("hello")
}

Developers should find easy working with Go's approach to concurrency.

In addition, Go's race detector adds to its appealing approach to concurrency by making the discovery of any race conditions within Asynchronous code easy:

<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Knock knock<br>
Race condition<br>Who&#39;s there??</p> &mdash; I Am Devloper (@iamdevloper) <a href=" HTTPS://twitter.com/iamdevloper/status/399991896862638081?ref_src=twsrc%5Etfw">November 11, 2013</a>

<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

Here are resources for developers to get started with Go and channels:

Team-Building and Ecosystem

Most developers use Java or C++ for performance intensive workloads. The Go development community is much smaller than those older languages like C++ and Java. According to a survey taken by StackOverflow in 2017, 62.5% of developers use JavaScript, 38% of developers know Java, 19.3% know C++, and 4.6% know Go. GitHub data shows a similar trend. Go is used more widely than languages such as Erlang, Scala, and Elixir, but it's less popular than Java and C++.

Go is an easy language to learn and is also easy to use. It provides only the basic features you need. The new concepts it introduces are the defer statement and the built-in management of concurrency with goroutines and channels. Any Python, Elixir C++, Scala, or Java developer who joins a team will learn the language quickly thanks to this simplicity. Building a team of Go developers is much easier compared to many other languages.

For a team of Stream's size, roughly 20 developers, the language ecosystem matters. Teams simply can't create value for customers if they have to reinvent every little piece of functionality. Go provides optimal support for commonly used tools, and libraries are available for Redis, RabbitMQ, PostgreSQL, template parsing, task scheduling, expression parsing, and RocksDB.

Go Bonuses: Gofmt Enforced Formatting, GRPC, and Protocol Buffers

Gofmt is a command line utility that's built into the Go compiler for formatting code. In terms of its functionality, it's similar to Python's autopep8. Developers don't like to argue tabs versus spaces, but formatting should be consistent (though the actual formatting standard doesn't matter significantly). Gofmt avoids all of this by having one official way to format code.

Be sure to read the next Developers article: GitHub Launches Preview of Organization Project Permissions API