![](https://static.wixstatic.com/media/c61b4f_298a4e21751a49d18b041b70881093e6~mv2.png/v1/fill/w_875,h_430,al_c,q_90,enc_auto/c61b4f_298a4e21751a49d18b041b70881093e6~mv2.png)
by Nir Makmal
What is the Go Programing language?
Go (short for Golang) is a programing language that was developed from many years of experience of world software leaders like Robert Griesemer, Rob Pike, and Ken Thompson in 2007, Go was officially announced on November 2009.
Their vision was to give to the world a simple language that can be kept simple also in the future, Also be able to decrease development time and bugs per line of code.
Go is a combination of several programming languages concepts:
It has high-performance utilization, Low footprint of memory consumption and disk usage that we have at C++ programing language.
It has a package manager like Node.Js, that gives us the ability to use and contribute very easily to many open source projects.
Go code is readable like python and JavaScript.
Go has a garbage collector like C# and Java, so the developer won’t need to handle memory allocations. And also can be very helpful to prevent from develops handling memory allocations which can introduce memory leaks to our product.
Why developing using the Go language?
Out of the box support for tests In order to support software projects agility, Go has a build In testing farmwork with an idiomatic format and methodology, Tests are a first-class citizen.
When writing code in Go this testing support will help the developers to write more testable, readable and maintainable code.
Slice - dynamic array
this will create a slice with an Array size of three StringsA new concept in the slice data structure, It abstracts the array data structure and gives to the developer a dynamic resizing array by just appending the new elements to the existing array.
This is very efficient compared to a language like Java that list resizing is done by creating a new array with x1.5 of the original array size.
Although this resizing at Java has amortized constant time - When adding elements at Java the average complexity is O(1) due to the size factor of x1.5.
Every ArrayList resizing will lead to more GC cycles since the old array reference is eligible to remove from the heap, which will impact our application performance.
Easily cross-platform support
Go support very easily cross-platform support, the source code can be compiled and run on Linux, Mac OS X, windows, x86 or Arm CPU very easily without the need to change the source code.
Go’s profiling tools We can use a powerful Built-In tool, Go’s profiling tool inorder to identify and correct specific bottlenecks of our Go program, It’s analyzing both CPU and Memory utilization and advanced profiling of Goroutines and a defined code blocks. Designed for microservices architecture Go approach is to encourage the developers to build self and small packages, this puts Go as a great language for a microservice software.
One of the principles of microservice is that the service should have a boundary context.
Each service should have a single responsibility, Therefore developing with Go can be very suitable for this principle.
Out of the box support for Concurrency Dealing with concurrency is very simple and thread-safe when writing code in Go using Go-Routines,
compared to other languages, Like Java or C# whereas the developer should be highly experienced in order to write a thread-safe program that needs to handle multithreading issues like race conditions and deadlocks.
Go support pipes in order to pass messages between threads that are called channels, This gives Go the ability to keep the code simple and to be thread-safe.
![](https://static.wixstatic.com/media/c61b4f_a85b793fe9b14ac4b9a82faf1c2a6b3a~mv2.png/v1/fill/w_875,h_617,al_c,q_90,enc_auto/c61b4f_a85b793fe9b14ac4b9a82faf1c2a6b3a~mv2.png)
When should we prefer to use Go?
Go ecosystem and the community keep growing, But still has gaps compared to Java, which has many stables frameworks like Spring that has support for DB, Security, AOP, Web, and other frameworks.
Developing with Go is ideal when writings microservice since most of the cloud and container architecture frameworks are written in Go.
Kubernetes, Docker, NATS are written in Go, Those frameworks are highly performant and with a very low memory footprint so it can be good to develop our product with Go and have the ability to contribute to those open source projects.
Adopting Go can have a slow start
Like any other new programming language, Go has a learning curve, It’s not only learning syntax but also learn idiomatic code style, New programming conventions, and concepts that can be challenging for Java or C# developers.
Go 1 has Lack of generic support
Although in the future generic support may be added, for now, The lack of generic is problematic when we want to write infrastructure frameworks that needed to be flexible and be with reusable code.
Today there are ways to do some kind of generic in Go code but all those ways are complicated and still need the developer to write some code that can abstract the code, Like using a general interface or using the reflect package.
Composition over inheritance
Go prefer composition over inheritance, So Interfaces are first-class citizens, This will make built-in support for S.O.L.I.D principles like the Open–closed principle - the class should be open for extension, but closed for modification.
Golang simplicity One of the main concepts of the Golang is simplicity, At the beginning writing a simple Go program can take a while, but since Go don’t have many reserved words the result of the code will be clean code with most likely some kind of error handling and unit tests since it part of the language.
In Conclusion Since the use and need for Microservices and cloud architectures is growing, When we consider moving to Microservices architecture we should try to write few services in Go in order to find out if Go can help us improve our software quality, performance and scalability, Also there is another programming language that can be suitable for Microservices called Rust that should take into consideration for microservices architecture. microservices-with-go-golang-what-why-and-when
Comments