All posts by Tirthamouli Baidya

Golang

Golang : A Hype or the Future?

Created by Robert Griesemer, Rob Pike and Ken Thompson for Google, GoLang was reportedly built by developers when they were waiting for the code compilation to complete in a project. The three main capabilities they certainly sought-after were the ease of coding, efficient code-compilation and efficient execution. Bringing all these capabilities in one language is what made Go so special.

Go is an open-source, procedural, statically-typed, compiled, and general-purpose programming language. The compiler was originally written in C but is now written in Go as well, which keeps the language self-hosted. the language has seen a lot of success in the last couple of years. A large portion of the modern cloud, networking, and DevOps software is written in Go, eg. Docker, Kubernetes, Terraform. Go is also being used by many companies for general-purpose development.

As the requirement for performance keeps growing, hardware continues to get sophisticated over time, the manufacturers keep on adding cores to the system to keep up with the ever-increasing demand. To handle such an increasing number of cores the system needs to maintain database connections through microservices, manage the queues and maintain caches. This is why today’s hardware requires a programming language that can support concurrency better, and that can scale up performance with the increase of added cores over time.

……………………………………………………………………………………………………

Golang versus Other Languages

Languages are compared predominantly on two factors 

  1. Ease of programming
  2. Efficiency

These factors are usually inversely proportional, meaning that any language that has high “ease of programming” usually has low “efficiency” and vice versa. Go holds the sweet spot with great efficiency and adequate “ease of programming”.

Discover the fundamentals of Golang in our latest article: Beginner’s Guide to Learn Golang: Your First Steps to Get Started. Dive into essential concepts and kickstart your journey with this powerful programming language.

Why “Golang” and not “C++” ?

Go and C++ are both compiled languages and both have similar speed(In fact, C++ is a bit faster than Go). But the garbage collector in Go is what sets it apart from C and C++.

Any complex program makes use of dynamically allocated memory, and this allocated memory needs to be freed when it is not required. If that is not done, the program would eventually use up all the available memory and crash. In the case of servers, it is absolutely required to do that as it is expected to run indefinitely. In C and C++, the user is forced to deallocate all the memory that they have allocated themselves or use a third party garbage collector. In the case of Go, all the dynamically allocated memory with no reference is automatically garbage collected, making it a lot easier to work with.

Concurrency and “Golang”

Many programming languages weren’t natively designed for concurrent programming. They lack proper design for concurrent execution, and so, they often slow down the pace of programming, compiling and execution. This is where Go comes as the most viable option to support a multithreading environment and concurrency both.

Eg: Language like python only allows one thread to access the interpreter at a time and essentially never runs two threads in parallel. So running two processor-heavy tasks at a time in python in separate threads would have the same if not worse result than running them in the same thread.

The Go scheduler unlike schedulers in other languages manages the concurrency fully by itself. It doesn’t map Goroutines to OS-level threads directly. Instead, it re-uses a few OS-level threads. This reduces the context switching delay significantly as most of the context switching is done at application-level and not Kernel level.

What is the call stack and why is it important in threads?

In case of threads, stack is used to store function return pointers (where to return the result of a function call) and static variables. Goroutine has a dynamic growable call stack which starts from only 4KB and can go up to the total memory capacity. Other languages, in contrast, have static stack sizes, usually of 1MB (determined by the OS).

This growable stack in Go is one of the key things which makes Goroutines light-weight. Where other languages can only have a few concurrent blocks, Go can have a lot more because of its dynamic stack size.

……………………………………………………………………………………………………

Conclusion

Taking into account all the offerings from Golang, we notice that it distinguishes considerably in terms of

  •  Faster compilation and execution
  •  Better code readability and documentation
  •  Offering a thoroughly consistent language
  •  Easy versioning
  •  Allowing development with multiple languages
  •  Allowing easier maintenance of dependencies

These features surely make Golang a contender for the next-generation programming language.

……………………………………………………………………………………………………

If you have any queries in this field, talk to Mindfire Solutions. For over 20+ years now, we have been the preferred Software Development Partner of over 1000+ Small and Medium-sized enterprises across the globe.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •