In past few years ago, there is a rise of new programming language: Go or Golang. Nothing can make a programmer crazy than a new programming language, I think right? So, I start to learning Golang in 2 years ago and finish learning by myself in 3 weeks with a real project, a e-commerce website of my office https://autonomous.ai.
I will not teach you how to code a simple program look like “Hello World!!” by Golang in this introduction article. Because I have lot of other articles to do that. I will only deep dive into subject that Why Golang is really good programming language.
Limitation of Hardwares
You can see the comparison of increasing the processing power with the time in below chart.
From the above chart you can see that the single-thread performance and the frequency of the processor remained steady for almost a decade
So, for the solution of above problem:
- Manufacturers started adding more and more cores to the processor. Nowadays we have quad-core and octa-core CPUs available
- They introduced hyper-threading
- Added more cache to the processor to increase the performance
But above solutions have itsown limitations too. We cannot add more and more cache to the processor to increase performance as cache have physical limits: the bigger the cache, the slower it gets. Adding more core to the processor has its cost too. Also, that cannot scale to indefinitely.
So, if we cannot rely on the hardware improvements, the only way to go is more efficient software to increase the performance. But sadly, modern programming language are not much efficient.
Golang Has Go-routines :))
But, most of the modern programming languages(like Java, Python etc.) are from the ’90s single threaded environment. Most of those programming languages supports multi-threading. But the real problem comes with concurrent execution, threading-locking, race conditions and deadlocks.Those things make it hard to create a multi-threading application on those languages.
Go was released in 2009 when multi-core processors were already available. That’s why Go is built with keeping concurrency in mind. Go has Go-routines instead of threads. They consume almost 2KB memory from the heap. So, you can spin millions of Go-routines at any time.
Some benefits of Go-routine of Golang:
- Go-routines and OS threads do not have 1:1 mapping. A single go-routine can run on multiple threads. Go-routines are multiplexed into small number of OS threads.
- Go-routines has channels to come with built-in primitives to communicate safely between themselves
- Go-routines have a faster startup time than threads.
- Go-routines allow you to avoid having to resort to mutex locking when sharing data structures. Go-routines have a faster startup time than threads.
Go: “compiled language” AND “uses garbage collection”
C, C++ over other modern higher level languages like Java/Python is their performance. Because C/C++ are compiled and not interpreted.
When you build an application using Java or other JVM-based languages when you compile your project, it compiles the human readable code to byte-code which can be understood by JVM or other virtual machines that run on top of underlying OS
C/C++ does not execute on VMs and that removes one step from the execution cycle and increases the performance. It directly compiles the human readable code to binaries. But, freeing and allocating variable in those languages is a huge pain.
And that is not trouble in Java, because Java has Garbage Collector to do that. So, you want a language which has “Both of Them”. That is Golang. Like lower level languages like C/C++, Go is compiled language. That means performance is almost nearer to lower level languages. It also uses garbage collection to allocation and removal of the object. NICE :-]
Code written in Go is easy to maintain?
I’m not sure. But in my mind, Golang does not have crazy programming syntax like other languages have. It has very neat and clean syntax.
Go intentionally leaves out many features of modern OOP languages(but, you can do OOP in my some other article).
- No classes. Every thing is divided into packages only. Go has only structs instead of classes.
- Does not support inheritance.
- No exceptions
- No annotations
- and no many thing which are so complex with amateur programmer
You may not like some points from above. But, it is not like you can not code your application without above features. All you have to do is write 2–3 more lines. But on the positive side, it will make your code cleaner and add more clarity to your code
Go is Programing Language of Google.
That’s awesome! Go is designed and supported by Google. Google has one of the largest cloud infrastructures in the world and it is scaled massively. Go is designed by Google to solve their problems of supporting scalability and effectivenessThat’s awesome!
More to that Go is also used by some big companies like IBM, Intel, Medium…
Is there a web framework like Rails or Django for Go? :((
Yes and so cool. You can search on google or git-hub, many and many cool framework result you can see on: Gorilla Web Toolkit, Gin-Gonic … They provide many of the facilities you would find in Sinatra or Flask or any other common framework which you knew.