Golang

Golang: An Introduction to Go Programming Language

What is Golang?

GO is the open-source, simple, and general-purpose computer programming language designed with advanced features. It is developed by the Google in year 2007, by the key developers Rob Pike, Ken Thomson, and Robert Griesemer. It is nick named as Golang

Golang is the compiled language, which means when we write and compile a code, it generates the machine code directly that makes it faster. It is efficient, high speed, and statically typed. It is influenced by C language, but it is much more than an updated version of C. It borrows various good ideas from multiple programming languages, such as Go has safety and high performance similar to C or Java, and simple with a feel of dynamically typed similar to Python or Ruby.

The syntax of golang resembles with C-syntax, but it has more simplified, clear, and concise syntax as compared to C/C++. To better understand the influence of other languages, consider the below image:

Why a new language “Golang”?

The Go is the new programming language, so before learning it we must know why this new language is developed, when there are lots of programming languages are already present. The below points explain the reasons behind developing this new language:

  • C/C++: C/C++ are the efficient system programming language, but did not grow with the computing landscape. From the last decade, no new system language has developed. So, there was the need for the new system language that can be appropriate for the needs of the evolving computer needs.
  • Java: It is little difficult and complex to work with Java, and it requires virtual machine to execute the code.
  • Ruby & Python: To work with Ruby and Python is very easy but not provide high speed or fast execution.
  • Before Go, a developer had to choose between efficient compilation (but not fast execution like .Net or Java), efficient execution with safety (but not efficient building and ease of programming like dynamic languages), or easy coding (but slow execution, and safety issues ); all three are not involved in any of the available language.

Hence, Golang is new programming language that addresses these issues by combining all the three, efficient and fast compilation, fast execution, and ease of programming with safety, in one language that make it simple yet powerful.

History of Go Language

Go is the new programming language created by the Google. The evolution of this language was started in year 2007, and it was launched publicly in year 2009. The development of GO was started by three key people, Rob Pike, Ken Thomson, and Robert Griesemer. Below are some milestones in the evolution of the golang:

  • The initial development of Golang was started in September, 2007 as a part-time project at Google Inc. by three engineers Rob Pike, Ken Thomson, and Robert Griesemer.
  • On Nov 2009, this project was officially announced, and released for the Linux and Mac OS X platforms with BSD-style license (Fully open-source).
  • On Jan 2010, the golang became the language of the year 2009.
  • From year 2010, it also started used in production at Google for back-end.

And currently it became one of the most versatile languages, that every developer keen to learn and use.

Features of Golang

Below are some popular features of golang that attracts the developers:

  • It is an open-source language with excellent community.
  • It is strong and statically typed, it means implicit conversion is not allowed, variables need to be defined at compile time.
  • It is much simple to use and can be easily understandable.
  • It is a high-speed language and mainly focuses on fast compilation as well as fast execution.
  • It is a garbage collected language; it means we don’t need any memory management in golang. Automatic garbage collection helps to easily write the concurrent code.
  • It has built-in concurrency that allows multiple processes to run simultaneously.
  • It has C-like syntax that make it to seem familiar to the programmers.
  • It has mixed features of object-oriented & procedural language, so it could be called as the hybrid language.

Missing Features of Golang

There are some features of modern object-oriented languages are still unavailable in Go, and these features are not provided intentionally to keep it simple, straightforward, and efficient. But there is a possibility that some of them might be implemented in future. These missing features are given below:

  • Method & Operator Overloading: These features are not included, to make it simple and confusion-free. Although method overloading is useful, methods with similar names may cause some confusion.
  • Implicit Conversion: The implicit conversion is not provided by this language, to make things easy, clear and more straightforward for the users.
  • Assertions: It does not provide the assertions so that the programmers can think to proper handling the errors.
  • Exceptions: Golang has not included exceptions, instead it uses Multiple return values and Panic function for error handling.
  • Generics: Currently generics are not provided by the golang, but as per the requirements, they might be added in future.
  • Type Inheritance: The concept of type inheritance is not available in this language. For the classes and type inheritance, Go applies different approach, as it does it with the help of interfaces.
  • Pointer arithmetic is also excluded.

Applications using Golang

  • Docker: It is written in Go language, and it contains a set of tools for deploying Linux containers.
  • Kubernetes: It is the container management system written in golang.
  • OpenShift: It is a cloud development platform as a service created by RedHat, written in golang.
  • Dropbox: Dropbox is using golang to scale its system more efficiently.
  • Google: Google is using go for various projects including download server dl.google.com.
  • Golang: It is itself written in Go programming language.
  • Similarly, Netflix, YouTube, Uber, MongoDB, etc., are also using golang in their respective projects.

Advantages of Golang

  • Fast Outcomes: It has fast compilation and execution, so you can get outcomes much faster.
  • Easy bugs finding: The errors can be found at compile-time only, as it is a statically typed language.
  • Higher readability: It has strict rules for the syntax, that increases its readability.
  • Rich Libraries: There are lots of standard libraries for performing different tasks in golang that make it a general-purpose language.
  • Built-in Concurrency: It enables to perform multiple processes to run simultaneously and efficiently with the help of concurrency feature.
  • Perfect for high-scalable programs: Since golang has built-in concurrency, so it is much suitable for big scalable programs.
  • Garbage Collector: It has garbage collector so there is no need of memory management.
  • Cross-Platform: It is a cross platform language, so can be used on different platforms including Windows, Linux, etc.

Disadvantages of Golang

  • Due to garbage collector, the real time execution is currently not possible.
  • Some important libraries such as UI toolkit, are not available.
  • Currently, it does not provide support for generics.
  • It is less flexible than other dynamically typed languages.
  • Pointers can be in Golang, but pointer arithmetic is not possible.

Is Golang Object Oriented or Procedural Language?

The Go language is nor completely object oriented neither a completely procedural or structural kind of language. But it could be called a hybrid language that has combined features of OO and procedural kind languages. Golang is created with combined good features of procedural programming, functional programming, and object-oriented programming. It can be understood in the below points:

Similar features of Object Oriented Dissimilar features of Object Oriented
GO has types and methods that allows it to follow an object-oriented programming style. It does not have type hierarchy.
It contains the concept of Interface that can be implemented different and more easy way. In general sense, it can’t be considered as the object-oriented language as C++ and Java because it does not contain the concept of Class and Inheritance.
Methods in Go can be defined for any sort of data, and can also be defined outside the structs. Go enables the functions to live outside of an object, similar to the C functions.

Prerequisites

To learn Golang, only the basic computer knowledge is required. Experience in any programming language will be an advantage.