DEV Community

Cover image for Let's Go!
JoeTags
JoeTags

Posted on

Let's Go!

As I finish the last week of my software engineering bootcamp, it is time to start focusing my energy on the job hunt. One of the companies I’m interested in working with lists a particular technology as a Nice to have’. So, this week, I decided to write my blog on golang, the Go language. Let the endless journey of learning continue.

The Go language was developed by computer scientists Robert Griesemer, Rob Pike, and Ken Thompson at Google and released in 2009. The mission was to address deficiencies in other programming languages used at Google. A few issues the trio sought to address was to create a language that was easy for a programmer to use. That meant having a minimal set of strict rules. They also wanted a language that would compile quickly and could scale to large codebases that had large teams of developers. Later in the article, we will get into some of the more technical details but first let’s get a better understanding of what makes Go unique.

If you head over to golang.com, the mission statement for the language reads:

“The Go programming language is an open-source project to make programmers more productive.

Go is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.”(golang.org)

Let’s break this down because if we can’t understand what the language is doing in plain English its going to be very difficult to learn how it codes.

The first sentence is pretty self-explanatory and we touched on this earlier that the language was designed to be concise, easy to read, and easy for programmers to remember all of the rules.
Now the next sentence gets a little tricky.

concurrency and multicore, networked machines

I think the best analogy I can give for concurrency is to think of a symphony with a conductor. The conductor is concurrency and the different instruments are part of the program or computing system that need to execute. Some processes may need to happen at the same time and some out of order(asynchronous) and they need to be able to enact an exchange of data without hitting a deadlock.

When we talk about multicore, networked machines, we are talking about multiple CPUs interacting within a computing system(s) and the programs that are being run on these systems.

while its novel type system enables flexible and modular program construction.

The type system is a way of assigning a datatype to a language construct to ensure that the resulting value is in fact what is expected. In this way, it speeds up the compiling of the language and allows for fewer errors from the programmer.

“The main purpose of a type system is to reduce possibilities for bugs in computer programs[2] by defining interfaces between different parts of a computer program, and then checking that the parts have been connected in a consistent way. This checking can happen statically (at compile time), dynamically (at run time), or as a combination of both”. Type System.Wikipedia.Wikimedia Foundation.18 October 2021.06 November 2021.https://en.wikipedia.org/wiki/Type_system#STATIC

This sounds a lot like Typescript. And it is. If Typescript is Javascript with a type system. Then Go, is like C with a type system.

Touching on the last part of the Go language mission is its use of garbage collection which most compilers have anyway but the Go version is much more robust. In essence, it can detect whether or not import statements are being used within a program and remove them if not being used. Think about how much memory space that can save! Think of how much more efficiently a program can run if each file doesn’t need to import data and then the compiler doesn’t have to scan over that data. Incredible.

For a more in-depth analysis of the differences between Go and Typescript, check out Amit Belazel’s Medium article, Micro-service Languages: Typescript vs. Go.

Alright already! Let’s see some code

To begin, navigate to the getting started tab on the Go website and download the latest version of Go. It’s super, easy to setup and took less than five minutes. After that completes, you can begin to code in your terminal of choice. I used VsCode but you should check to make sure your terminal is compatible.

There are instructions in the tutorials section that can guide you on how to set up your first Go directory. Now, we can have some fun!

After you you initialize your directory and cd into a file. You can create a file with .go.

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
Enter fullscreen mode Exit fullscreen mode

Now, in the command line, type: go run . and voila! You have successfully created your first Go program.

So, now that you’ve had the lecture and have a more general understanding of what makes Go tick. Get out there and give it a try for yourself.

Discussion (0)