DEV Community

Cover image for Go .. C of 21st century
Bek Brace
Bek Brace

Posted on

Go .. C of 21st century

#go

Go language, it is a statically typed compiled language and it is often described as c for the 21st century!

It was created at google in 2007 by legends who really know their stuff like Ken Thompson the inventor of the (b) and (c) programming languages; and then version 1.0 was released as open source software in 2012; and the was design was meant to be simple and efficient and that's why we call it go.

The source code is compiled down to machine code which means it generally outperforms interpreted languages but it's famous for its extremely fast compile times made possible by innovations to dependency analysis and even though it's a statically typed language it performs type inference to deliver a syntax that is very concise and practical.

It also has a package and module system making it easy to import and export code between projects to get started install go and then open an empty directory on your system.

Create a file ending in go then add package main at the top to create a standalone executable then
declare a main function which is where your program will start executing

Image description

Go has a standard library of core packages to handle common requirements like math networking or formatted io by importing "fmt" we can print a line to the standard output then run the go build command and it quickly compiles the source code and dependencies into an executable binary.

Image description

Image description

When it comes to dependencies we can also link to remote packages on github.

Run go mod init from the command line and that creates a go module file that enables dependency tracking.

Go is like a concise version of c or c plus plus if you know any of those languages, you declare a
variable with the var keyword followed by its name and type and initialize it with a value or you might use the short assignment syntax to replace var and let go automatically infer the type and you can define multiple variables from a single line go has all the other features you would expect in a programming language like arrays maps loops and control flow but also allows you to store the memory address of a value using pointers while disallowing pointer arithmetic which often leads to dangerous and unpredictable behavior in
addition it supports concurrency with go routines which are functions that can run at the same time as other functions by utilizing multiple threads on a cpu.

Top comments (0)