Go, Go, Go, GoLang

GoLang started back in 2009. I have been hearing about Go as a hot new language for the past almost 10 years. GoLang is fast. GoLang compiles the code into binary. The performance of Go is comparable to C and C++. Go (shortened version of GoLang) was created to be easy to maintain. As I’m beginning to explore the language, I’m noticing how strict the compiler is in some things that you try and code.

Some of the interesting things I have noticed so far is each directory can become its own package. In order to have an executable binary, you need one file in your folder with the package main, and the main function.

When you declare a variable in Go, you have multiple ways of declaring them. If you have a string, you can just write

var str = “Blah string”

If you want to declare integers you can write

var myInt int

or

var myIntA, myIntB int = 1, 2

and there’s another way to declare a variable which is

someVariable := “String string”

One thing I really like in GoLang is there are built in unit test tools. When you want to run tests on your code, create a new file with the same name as the file you want tests on, and append “_test” to it. For example, if you named your file FooBar.go, create a new file named “FooBar_test.go”. If you want to test any of the functions from your FooBar.go file, you prepend the word Test to it. For example, the function looks like “func TimeCounter()”, the new function you would create to test it would look like “func TestTimeCounter(t *testing.T)”. When you have written all the tests you want to write, just type “go test” in the command line in the directory you want to run your tests.

As I learn more and more about Go, I know I will find more use-cases to use Go over other languages. For example, Go gives you the ability to have concurrent programming. Concurrency is the ability to have different parts of a program, algorithm or problem to be executed in any order without affecting the final outcome.
What use do you have for concurrency? One use case could be when you’re consuming large files, and parsing them in chunks. Here’s an example, some people wrote a test using node.js (without concurrency) to consume a really large file. From reading the article in the references section, it seems they were parsing a 70GB file. In node.js, it took roughly more than 28 minutes to complete, in Go it took a bit over 4 minutes to complete. Wow! Imagine if you’re a company, say a weather company processing large GRIB2 files, this would save so much time when you want to parse files with large amounts of weather data.

I have a passionate interest in programming for Numerical Weather Prediction (NWP), which is a field used in Meteorology for creating the weather models. For some of the reasons I outlined in the previous paragraph, Go is a language currently being used in meteorology. I don’t know which if any official government agencies are currently using Go in their weather data processing, but I have found a few projects writing Grib2 parsers in Go. I have no affiliation with any of these blogs/projects, but I am always interested in pointing people to anything interesting: https://nilsmagnus.github.io/post/grib2-adventures/ https://github.com/eugecm/gometar https://github.com/brockwood/gogrib2

Who else is using this Go language, and what are they using it for? Disney is using Go to stream their videos online, Docker uses Go, Facebook, Twitter, YouTube use Go, BBC uses Go. This video might be a good place to get an up date from last year on what the state of Go is, and the presenter also tells you a bit more about what companies are using Go for: https://www.youtube.com/watch?v=5UG57xQL_RE.

As I learn more and experiment more, I will write more about the latest I am learning. There’s a major release being worked on in Go, and I think it would be of great use to anyone interested in Go to follow the latest drafts and to participate in how you want the future of Go to be shaped. Go here to keep up to date and learn how you can participate https://go.googlesource.com/proposal/+/master/design/go2draft.md