Acquaintance with Go Language
In this post I’d like to share my recent experience from learning Go programming language.
I’ve decided to dive into Go by taking “Programming with Google Go Specialization” @ Coursera:
https://www.coursera.org/specializations/google-golang
The specialization consists of three courses:
The courses are taught by Prof. Ian Harris from University of California, Irvine.
In my opinion the specialization provides good introduction into Go language, even though I found some of the concepts as very basic.
My Start in Go
Let me start by saying that I’ve spent most of my professional time coding in C# and Java programming languages, and I although I feel equally comfortable with both, I must admit that C# is my home court.
We all know that .NET core was a game changer. It allowed to containerize .NET applications and run them in Linux servers. Since its release, the great paper by Microsoft “. NET Microservices: Architecture for Containerized .NET Applications” became my desk-book. It thoroughly discusses architectural design and implementation approaches using .NET Core.
Putting platforms interoperability and even performance considerations aside .NET core undoubtedly offers great programming experience and flexibility.
Since Golang is rapidly becoming the language of choice for building cloud-native and following the saying “ doing something once is better than hearing about it a hundred times”, I decided to gain some hands-on experience with it.
Go Programming Features
Getting starting with Go was pretty straightforward process: downloaded it from here, and since I already had VSCode, just added a few Go tools and extensions.
After completing a bunch of assignments (and of course the canonical “Hello Go” application :)), I’ve immediately noticed unique features (subjectively speaking :))
- Is Go object oriented? The answer depends on what language you’re coming from. At first glance, Go code doesn’t look much object oriented, but going deeper I understood that Go just takes a different take on object orientation. It is achieved with structs, interfaces and methods<->types association. Also, Go favors composition over inheritance and makes implementation of design patterns with a less bloat and same flexibility.
- Functions visibility — controlled by naming convention. Public functions start with capital letters when internal ones with lower case letters. The benefit of doing it this way over using scope identifiers (public, private, etc.) is that it enforces you to follow proper naming conventions.
- First-class functions — Go allows functions to be assigned to variables, passed as arguments to other functions and returned from other functions.
- Function Returning Multiple Values — in Go language, you are allowed to return multiple values from a function, using the return statement. This feature is commonly used in idiomatic Go, for example to return both result and error values from a function.
- Variadic functions — functions that accepts a variable number of arguments.
- Pointers — reminded me my struggling with them while learning C/C++ in university. C#/Java do not have pointers, however it could give you more granular control when it comes to memory management or performance fine tuning.
- Slices — really cool data structures that give you powerful interface to sequences. Under the hood they draw on arrays, but with much more flexibility and convenience compared to arrays.
- Concurrency — Go offers great support for concurrency and makes it fairly easy to implement a concurrent system with channels and waiting groups. Go supports this at the language level and implements it with lightweight threads of execution — Go routines.
- Documentation — every exported/public function should be commented, otherwise you’ll get compilation error.
Conclusion
While comparing Go to C#, I think that Go really opts for simplicity:
- It is a simple language, designed with minimalistic mindset.
- The built-in library contains the most things you may need to get started with.
- In order to keep the language simple and avoid complexity, generics are not supported.
- The standard library is self-explanatory and consistent.
- Consistency is enforced by the language for better readability and maintainability.
I feel like Go designers did really good job to avoid accidental complexity and built it from the ground up with the “Less is more” mindset.
Published By
Originally published at https://www.linkedin.com.