Welcome To Golang By Example

About GOLANG

This is chapter 1 of the golang comprehensive tutorial series. Refer to this link for other chapters of the series – Golang Comprehensive Tutorial Series

Below is the table of contents for the current tutorial.

Overview

This is the first tutorial that will give you an introduction to the GOLANG language. Go is a statically typed, compiled programming language. It is an open-source language and was developed at Google by

Since GO is an open-source programming language, it is hosted on Github and  is open for contribution by anyone.

https://github.com/golang/go

Go has C style syntax but provides memory safety, garbage collection and inbuilt concurrency.

History

GO had its first stable release in 2011.

What makes GO different

Let’s see some of the things which makes go different from other programming languages.

Simple to Use Syntax

Go is syntactically similar to C and has a really simple syntax. It is easy to learn with little facets. It is not overwhelmed with features and thus it is easier to write readable and maintainable code in GO. Also, GO has very few keywords compared to other mainstream languages. The GO specification mentions 25 keywords.

https://golang.org/ref/spec#Keywords

Compiled Language with fast Compilation

Go compiles into a native executable. Its compilation is really fast and it is attributed due to a couple of reasons. You can check out this link for more details related to why GO compiles fast. When you build a GO program the resulting binary is what it is. There are no other dependencies. You can port this binary to any platform which supports GO and it can be executed there. This is different when you compare it with other programming languages such as JAVA, Python, where to create a self-contained binary there are a bunch of dependencies that need to be taken care of and packed along. There is no concept of Dynamic Link Library in GO in fact it supports static linking. GO is statically linked with all the libraries into a single standalone big fat binary.

Static Type Language

Even though GO has a really neat syntax, it is a strong and static type language. There is no implicit conversion allowed in the language. Since it is the static type most of the errors related to mismatched type are caught during compile time unlike languages like Python, Ruby. etc

Garbage Collected

Go is a garbage-collected language. That means you don’t have to worry about freeing up memory. So you don’t have to be bothered about malloc() and free() statement like in C, C++

Built In Concurrency

GO through its inbuilt concurrency tries to solve two major problems associated with other languages

Go approach to concurrency can be best described by

Do not communicate by sharing memory; instead, share memory by communicating

GO tries to achieve the above through its two concurrency primitives

Standard Library

GO standard library is rich in features and support for almost everything which is needed for building all types of applications. There are also tons of packages which have been created by the GO community on top of GO standard library which is ready for use and available on Github

Tooling

GO support for tooling is strong and rich. It has tools for code formatting, unit testing, race detector, linting, memory analysis tools, tools for generating documentation  etc.

Comparison with other programming languages

With all the above advantages if you compare with other programming languages you will notice

With Java

With C/C++

With Python/Ruby/Java Script

Disadvantages of GO

Let’s see some of the disadvantages of go as well

No inheritance in GO

Go doesn’t have classes. It has structs. Even though the functionality of structs of pretty similar to classes but GO favors composition over inheritance. GO also doesn’t support type hierarchy. It doesn’t have keywords such as extends or implements as in JAVA. So in that terms GO is not a pure OOP language. The missing of such features might seem odd to coders who all well versed in coding in an OOP manner.

No Generics in GO

Due to the absence of generics in GO, it expects you to write a very explicit code for what you want to do. Although there are talks of adding Generics support to GO very soon.

No Compile Time Polymorphism or Function Overloading

Function Overloading is not possible in GO. See this faq for the reason https://golang.org/doc/faq#overloading

According to the above faq, things are simpler without it. Although there are some workarounds to achieve the same. Can refer to this link

https://golangbyexample.com/function-method-overloading-golang/

Conclusion:

To summarize what we have discussed so far

This is the basic introduction to golang. Hope you have liked this article. Please share feedback or improvements or mistakes in the comments.

Next Tutorial – GO Installation