Why Golang and Let’s set it up
buZz : Go is expressive, simple, concise, clean, efficient, open source …….……. and a lot
Now let's see why it’s everywhere & everyone is talking about it and what actually the Golang brings to the party
Gois an open-source, modern programming language developed by Google
Why a New Language? from Google
To understand that we have to look that the common languages used by Google at the time of Golang is being designed, mainly three were languages which are keyPython, Java,andC/C++.
Each of these languages in and out are very powerful, however the go designers started to recognize there were some limitations that google was running into that might not be able to fixed by the designs of the existing languages likePythonis easy to use, but slow(because its an interpreter language),Javasuffers from its Increasingly complex type system andC/C++has some natoriousslow compile times and complex type systems. all of the these langagues were created in a time where multi thearding works rarely, almost every application was created just have to focus on single thread at a time
So.. What Go bring to the party
Firstly go isStrong and Statically typed language,So what we mean by Strongly typed, that the type of a variable can’t be changed over time when you declare a variableAto hold an integer its always gone hold integer you cant put a boolean in it, and statically typed means all of those variables have to be defined at compile time (Go also have features that allow you to get around its type system). There is a lot of effort taken to that the compiler do as much work to understand what you talking about variable, so you don't have to explain every time about variable types and things like that
Key features
while it's novel type system enables flexible and modular program construction
Simplicity
It’s a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.
Fast Compile times
Go compiles promptly to machine code yet has the advantage of garbage collection and the power of run-time reflection
Garbage Collection
You don't have to manage your own memory (certainly you can manage) Go run time is gone manage it for yours. Now Go is really really fast that almost you don't know that the garbage collection happened
Built-in Concurrency
Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines
Compile to standalone binaries
Go compiles down to a standalone binary which means you compile go application everything is going to be bundled into a single binary that's related to the go application, go runtime, any libraries, DLLs. Version management at runtime becomes trivial you only have one binary to maintain
Powerful Standard Library and Tool Set
This programming language also comes loaded with a robust standard library. These libraries offer ample components that give developers an escape from turning towards third party packages anymore.
Also, it offers a wider range of tools that makes the development process efficient. This includes:
- Gofmt:It automatically formats your Go code, which eventually brings a major impact on readability.
- Gorun:This tool is used to add a ‘bang line’ in the source code to run it, or run a similar code file explicitly. It is often used by Go developers when experimenting with codes written in Python.
- Goget:The Goget tool downloads libraries from GitHub and save it to your GoPath so that you can easily import the libraries in your app project.
- Godoc:The tool parses Go source code, including comments and creates documentation in HTML or plain text format. The documentation made is tightly coupled with codes it documents and can be easily navigated with one click.
All enough much more interested in starting with Golang code?
Let's start with Golang installation
gotohttps://golang.org/dl/and download the latest binary release suitable for your system
macOS package installer
Download the package file, open it, and follow the prompts to install the Go tools. The package installs the Go distribution to/usr/local/go
.
Installation takes couple of seconds to install
The package should place the/usr/local/go/bin
directory in yourPATH
environment variable. You may require to restart any open Terminal sessions for the change to result.
So now its time to try something in Golang
make the directorysrc/hello
inside your workspace, and in that directory create a file namedhello.go
that looks like:
Then let's build it with thego
tool:
The command above will build an executable namedhello
in the directory beside your source code. Execute it to see the welcome from Go:
If you see the “hello, world” message then your Go installation is working.
Congratulations
So that's it for this article finally, you wrote your firsthello worldinGolang