First off, the Go programming language probably wins the "Goofiest Programming Mascot" award of the year, by far. What is Golang, though? A lot of programmers may have seen passing reference to the language, off and on for the past 7 years, but may not have given it much thought. After all, there are usually a ton of growing pains with any relatively new language. Thankfully, Go appears promising, thanks to a solid support base and relatively active development since its inception.
What is Golang About?
For a bit of background, Go is an open source programming language created by 3 engineers at Google in 2007. Robert Griesemer, Rob Pike, and Ken Thompson created the language, apparently, as a truly modern language since the advent of multi-core CPU's, threading, and increasing demand for good concurrency. In essence, it is designed to better bridge the gap between lower level and more high-performance languages like C-based languages, and higher-level languages like Python, Ruby.
Where lower level languages can usually offer substantially greater performance, coding, code management and testing can become increasingly more difficult. For higher level languages, while ease of use is often an attraction, when you start dealing with things like apps and high traffic overhead, the performance issues and/or lack of concurrency/scalability can be very stifling. As with many other past and present language attempts, the whole "Jack of all trades, master of none" thing can often have a lot of downsides. Ultimately it comes down to a matter of determining what compromises are worthwhile for you and/or your team to make.
So what are some of the attractive features with Go?
- Built-in concurrency
- Static typing
- Productive and readable syntax
- Fast compilation times
- Awesome, out of the box debugging, testing, and building tools
1. The Tools:
go build
The 'go build' command allows you to compile your program to a single, executable, binary without any additional files. This is simply awesome for certain uses. For example, you could build simple programs to improve efficiency and serve specific functions for less-technically-inclined team members, while being able to provide it to them in a single executable they can simply double click. Think about how nice that would be to give a team member a single "thing to click on" to run some report, generate some file, etc. and otherwise streamline their daily efforts.
go fmt
The 'go fmt' command will format your package source files in proper, idiomatic Go-fashion. It may not work 100% of the time, I honestly do not know, but it seems to work much of the time which is downright awesome and efficient.
go run
Need to get a simple web server up quick? With just a very few lines of code, to set your main server functions, plus 'go run' on your package source, and you are up and running within seconds. Even if you don't plan on running a public-facing web server with Go, it could be used to really streamline certain internal company processes. For example, say you have a team that primarily codes in Python or at least uses it frequently. Maybe you might choose to build a simple listening server to pick up certain file outputs (if, for example you have Python scripts running and generating files), maybe handle post-processing needs concurrently with Go, or simply using Go to delegate that processing to other programs in an efficient manner.
Go has a number of other great tools, but in my minimal experimentation with the language, those are 3 of the ones I've liked the most.
2. Concurrency:
Go offers good concurrency in the form of 'goroutines' and channels. Additionally, Go can be used for parallel programming, however it is important to note that there is no race condition safety, so it's certainly not foolproof. Goroutines are lightweight threads that are managed by the Go runtime. Channels are effectively the conduit that lets you feed data between goroutines to other goroutines.
3. Fast Compile Times:
One of the great features with Go is build efficiency and speed. Although you do not need to compile every Go program, and can instead simply 'go run' them, for those that need it, this is a very welcome characteristic. For any of the low-level programmers out there, especially anything C/C++-based, you are already well-aware of just how much compiling code can suck, and just how much time it can take. Thankfully, this was one of the issues Go's designers sought to address up front. Some of the ways they addressed it:
- Expressive and lightweight type system
- Doesn't have templates or inline functions. Go doesn't need to perform instantiation accordingly.
- Generates assembly code sooner. Optimizer works on the assembly code, as opposed to the source code.
- Compiler generates instructions in binary instead of text
- Dependency Management: The compiler only includes packages you import directly. As they say, "Everything you want; nothing you don't."
There are a number of other great features as well, such as the relatively robust libraries Go comes with. Overall, I've had a fun time learning the small amount of Go I have so far. Golang.org also has excellent documentation, and I highly recommend checking out "Effective Go" to make more sense of the language's characteristics. There are already a number of cool programs built in Go, such as the Hugo static site generator. Hugo is what first interested me in Golang, and is proving to be one of the nicest development workflows I've had the pleasure of dealing with in quite awhile.
Although the language is still relatively new in the grand scheme of things, thanks to the whole MOOC phenomenon, there are already a number of training resources and Go-specific classes out there to help you learn how to code in Golang. For example, here's a wonderfully straightforward, enjoyable, and comprehensive Golang class on Udemy from CSU Fresno professor Todd McLeod. Get on it quick if you're interested, as it's currently discounted to $24 for TWENTY ONE HOURS of training! Bonus points if you can maintain your composure while watching Todd at 2x speed!
Golang 'gopher' image courtesy Renee French: http://reneefrench.blogspot.com/