CODE REVIEW SERIES
The best practices before submitting a code
August 11, 2020
Golang V/s Java & C++
August 11, 2020
Show all

Going the Golang way

Hello friends, I hope everyone is having a good time. Today, I am going to talk about a new programming language that is already a success. A couple of years back, a language known as Go or GoLang came into existence. I know that nothing makes a developer crazy than a new programming language! But trust me guys, going crazy with GoLang is worth! 

Go programming language is one of the most popular languages from the past 10 years. Veteran Unix hacker Rob Pike is one of the founders of Go Programming language. In late 2017, he mentioned in his post titled “Go: Ten years climbing”, that the rapid development of Go programming language in the past 10 years is something unforeseeable, especially to the founders themselves. Interestingly, Go programming is now the latest programming language being utilized by Cloud computing.

I have many friends from the IT field and they always keep asking me if it is important to learn Go programming language and whether it will become the future trend or not. For all my friends with such questions and for every one of you, today I would like to share my experience of learning Go programming language. I would also be discussing the key factors required for the development and the widespread utilization of a programming language. So let us begin!

My Go Learning Experience

By the end of 2009, Google had open-sourced Go programming language. I knew this fact but I never gave it a thought because I was already working for Amazon till 2013. Thereafter, I joined Google in 2014 and I started to learn the Go programming language. The reason for learning Go was that a lot of Google systems have been written in this programming language. So learning Go was important as well as necessary. So how much time did I take to learn this language? I mastered the basics of Go programming language in less than a day and I also managed to submit a bug fix using it.

So what was my impression of Go programming language at that time? This could be summarized in these points. 

First of all, GoLang is quite easy to get started 

The grammatical rules of Go programming language are very easy. They are plain and simple without any tricks. There is no prior experience required for learning or implementing Go which makes it suitable for new programmers. The learning curve of GoLang is very low and it’s pretty much easy to master this language. Go provides proper error handling and there aren’t any bad defaults which lead to crap.

Second, parallel programming and concurrency control are free of hassle

Goroutine and Channel provide a good amount of language-level support for concurrency and parallelism. Programming languages like C, C++, Python, and Java have a more complex form of concurrent and asynchronous control. They have higher chances of encountering errors as well. Such problems have bothered me for years but Go is tackling such issues in a better way. According to me, go is certainly a pleasant language as compared to other mainstream languages.

In terms of Go programming language advantages for Multithreading and concurrency control over its rivals, you may refer to the article on medium. I have also included the link for your convenience.

Let’s talk about multi-threading first

It should be noted that most of the modern programming languages like Java, Python, etc, belong to the single-threaded environment from the 90’s. All these programming languages support parallel programming through multithreading. But on the other side, they don’t support parallel programming in a first-class way. 

I would like to explain this issue with an example. If you create a new thread in Java, it is not memory efficient. Every thread consumes approximately 1 MB of the memory heap size. Now consider the same scenario of creating threads for server related tasks. If you want to build a server which is handling millions of HTTP requests per second, Java will be spinning separate threads for each and every incoming HTTP request! Even if most of the times, the thread is I/O blocked, it will be using 1 MB of memory approximately. Overall, this will put tremendous pressure on the heap and will result in shut down due to “out of memory” issue. This isn’t only limited to Java, but any language that uses OS threads as their primary means of concurrency will result in the same situation.

Go has solved such multithreading issues because it was released in 2009. During that time, multi-core processors were already available. So when Go was being built, concurrency was considered. So instead of threads, Go has goroutines.

Now you must be thinking what goroutine actually is? Goroutine is a function that executes independently and is launched by a go statement. The advantage of goroutine is that it is very cheap. By meaning cheap, I mean that it’s practical to have hundreds or thousands of goroutines because each of them occupies 2KB memory from the heap. If you compare 2KB with 1MB, it makes a huge difference! Goroutines aren’t threads, they are multiplexed dynamically onto threads whenever needed to keep all the goroutines running. It is possible that there might only be one thread in a program with thousands of goroutines.

Comparing the same scenario of HTTP requests, to handle a million HTTP requests, Go can spin a separate goroutine for each request. In short, Go can conveniently spin millions of goroutines at any time as each goroutine would only acquire 2KB of memory from the heap. This makes it quite practical, efficient, and optimum for real-time situations.

The other aspect in which GoLang is doing a great job is its simplified concurrency control model

Most programming languages like Java, Python, etc. always have issues with concurrency control. This is because programmers need to write complex code to execute things like synchronization, locking and memory visibility. This further leads to problems such as threading-locking, race conditions, and deadlocks. Due to this, it becomes difficult to create multi-threading applications in these languages. Communication between two or more threads also becomes quite difficult. Under such difficult situations, Go comes to your rescue. This is because Go has Channels.

Channels can be considered as pipes through which Goroutines communicate. Like water flows from one end to the other in a pipe, data can be sent from one end and received at the other end using Channels. An important thing to consider here is that Sends and Receives to a channel are blocking by default. This means that when a data is sent to a Channel, the control is blocked until some other Goroutine reads it from the channel. Similarly, when data is read from a channel, the read is blocked until some Goroutine writes data to the channel. Due to this system, Goroutines are able to communicate effectively without the use of explicit locks or conditional variables.

The third thing I noticed is that GoLang provides good library support

The most commonly used libraries such as JSON, XML, SSH, database connectivity, etc, are all included in the Go language lib library. These libraries are well designed and well composed. These libraries are also improving overtime with an ecosystem being built around Go.

There are more than 200 programing languages in the world, however, only 20 of them are widely used. So Let us find out what makes any programming language popular

Historical happenstance is the first thing that makes a programming language successful

The languages that are introduced at the right place and at the right time for solving the most critical problems become a hit. This is because an existing ongoing problem would be solved. For example, JavaScript was created hastily within 10 days for Netscape. It slowly became an integral part of every web browser which further made it the most popular language over the past decade.It is the only native scripting language in the web browser and the language that is supported by all browsers. If you tried to get a browser implementer to add support for some other language, they would reject your proposal out of hand.

Something similar happened with Java as well. Before Java was invented, C was the most popular programming language and is till date considered the foundational language of the entire IT industry. But C had two major issues. The first problem i.e. portability issue is solved by Java virtual machine. With the help of Java Virtual Machine, Java can run on any platform without recompiling as long as Java Virtual Machine is installed on the platform. This is also known as “Write once, Run everywhere” mechanism. The second problem with C is manual memory allocation this could be error prone. My first programing language was C. I still remember that I used to spend  a huge chunk of the programing time on troubleshooting memory allocation issues while programing with C.

This is solved by automatic memory management.  Java has built-in garbage collection, which is considered as one of the language’s finest achievements. It allows developers to create new objects without worrying explicitly about memory allocation and deallocation. The greatly increased the development productivity. 

The next point is related to Corporate Sponsorship because it matters a lot

It’s not only about the programming language, but also about who is pushing it! For example, Java was being backed up by Sun Microsystems, IBM, and Oracle for developing enterprise applications. Swift was being pushed by Apple for being Objective-C’ successor. When big companies endorse such a programming language, developers start believing in the language. Investment also helps in research and development of the language. Overall, the value of the language improves.

Thirdly, Association of the language with any Killer application is the trump card to make a programming language successful 

One of the classic examples to be considered here is about Linux. It is written in C. Similarly android apps are written in Java. So if any developer wants to fix a bug or create an android app, they would have to learn C or Java. So this is one of the ways how these programming languages become popular.

Lastly, A successful programming language should always be easy to learn, understand, and implement

The language should be easy to learn and use, it should have a shallow learning curve. For example, Python is a language that has been recognized by developers as an easy language and is one of the reasons why it is among the top 3 most popular languages.

Let’s get back to Golang

We came up with 4 factors that make a programming language popular. Let us now match the features of Golang with these factors. 

-Firstly, Go solves the concurrency control headable in multithreaded programing.

-Secondly, Go is designed and supported by It giant Google.

-Thirdly, Go’s killer application is Docker. Yet, it is by no means the hottest virtualization technology.

-Fourth, Go is very easy to use and implement.

By comparing these points, we at least know that Go fulfills most of the requirements for becoming a dominant programming language in cloud computing. It certainly has a good future in cloud computing, but not in other domains. I will explain “why?” in the next section of our Go series.

It’s time to summarize what we have discussed today

Today, we talked about a promising programming language in the cloud computing sector which is known as GoLang or Go. My experience of using GoLang has been pretty good. It is providing great concurrency control and parallel programming features with easy implementation. Features like Goroutines are also helpful in boosting up multithreading. A good library support is provided as well! GoLang is also fulfilling the necessities of any popular programming language and is already showing its potential. According to my experience and analysis, the language certainly is on the way towards success. Developers working with cloud computing should give it a Go!

Also, checkout our Code Review Series

Tao
Tao
Tao is a passionate software engineer who works in a leading big data analysis company in Silicon Valley. Previously Tao has worked in big IT companies such as IBM and Cisco. Tao has a MS degree in Computer Science from University of McGill and many years of experience as a teaching assistant for various computer science classes.

Leave a Reply

Your email address will not be published.

LEARN HOW TO GET STARTED WITH DEVOPS

get free access to this free guide, downloaded over 200,00 times !

You have Successfully Subscribed!

Level Up Big Data Pdf Book

LEARN HOW TO GET STARTED WITH BIG DATA

get free access to this free guide, downloaded over 200,00 times !

You have Successfully Subscribed!

Jenkins Level Up

Get started with Jenkins!!!

get free access to this free guide, downloaded over 200,00 times !

You have Successfully Subscribed!