#TIL Go Has Got It Going On

Doing some research for my upcoming Prairie Dev Con talk on Go, I’m learning some pretty interesting and neat stuff about the language.

Go (or “golang” if you’re doing google searches) is a programming language created by people at Google to address some of the concerns with modern programming languages, as well as giving people used to creating systems with C or C++ a bit more power with a lot less complexity. While it has a bunch of cool features like remote package management, auto-generating documentation, and statically linked binaries, the one I want to talk about is its concurrency model.

With Go, you can start a lightweight process by simply saying “go MyFunction()”. The important part of this is the “lightweight” part – in some existing concurrency and/or threading frameworks a thread can take up a minimum as 1 megabyte and start to force CPU context switching, without the developer even knowing they’re eating up system resources. With Go, they’ve taken care of that for you by providing a lightweight system out of the box.

Speaking of taking care of things for you, when you start a “goroutine”, it could be processed on any available core on the system, making your applications automatically able to take advantage of the parallel processing power available on most modern CPUs. Again this can be a huge headache in other programming languages which usually rely on external packages or advanced configurations to provide the same functionality.

Of course, you still run the risk of creating race conditions when working with multi-threaded or parallel operations. Go tries to alleviate some of these issues by providing “channels”, which are more or less streams you can use to read and write objects and data between goroutines. When your goroutine tries to read from a channel, it will automatically block until it receives something, providing an easy way to synchronise between routines without having to manage any sort of shared state or lock.

There’s lots of other cool things to learn with golang, but for more information you’ll just have to attend my talk at Prairie Dev Con!