Why you should (and shouldn't) use Go (aka Golang)
Some advantages of using Go:
Go has the cutest mascot ever. OK…, Let’s see the real advantages.
Compiled
- There is no VM. It compiles directly to the machine code (if we exclude Go’s intermediary assembly) which is fast, fast and fast (did I say fast?).
- Fast compilation. The programming language design is built for fast compilation in mind from the beginning.
- Compiles cross-platform to OS X, Linux, Windows, and many others.
- Creates only one executable file output after the compilation without any dependencies, so that you can upload it anywhere which Go supports and just run it. Or just compile it there after you upload the code. No dependency hell.
Safe
- Strong and static typed.
- Garbage collected. It cleans up your dirt after you and integrates the whole garbage collection system into your executable binary.
- Reliable. You can really create a very reliable software with Go. Because the inherent language design prevents you from doing awful stuff with it. For example: It has pointers but they’re mostly not dangerous as in C because the memory is being managed by Go and pointer arithmetic is not advised by default.
However, this reliability is only for the compilation part, in runtime, nasty things can happen, if you want maximum run-time reliability, you may prefer, for example, Rust instead.
Paradigms
- It’s an imperative language which is an advantage and a disadvantage to some people.
- Supports a different kind of object-oriented programming (OOP). I come from many OOP languages like Java, C#, Ruby, but, Go gets the best practices from OOP and lets you program differently, in a Go way.
Go wants you to compose things not inherit like in other OOP langs.
- Supports interfaces (as in OOP). This helps to compose things. Does “Polymorphism” ring a bell? Go does not force you to mark your types as “implements this and that interface”, it inferres this from the functionality the type supports. This increases flexibility and composability.
- Go lets you attach functions to any type. This flexibility lets you compose your programs from smaller things. When a type implements the functions of an interface it’s said that the type satisfies that interface and can be used in places that desires that interface.
- Supports functional programming (FP). For example, Go supports anonymous functions, closures and first-class functions.
Concurrent
- Built-in concurrency. There are no heavy threads but channels.
- Ability to program and structure your programs in a synchronous manner but actually it’s asynchronus. Channels hide that complexity and lets you structure your programs in a more maintainable way.
Standard Library
- Almost all of the things built into its standard library (which is the library that comes with Go by default) like http fetching, json parsing, and encryption. So, this makes you faster and prevents fragmentation in the ecosystem (most of the time).
Tooling
- Great built-in command-line tools. Auto-formatting your code, checking race-condition issues, auto-documentation, test coverage reporting, refactoring tools etc.
Some disadvantages of using Go:
- No generics support. Actually, I’m not counting this as a disadvantage although I put it here. Because it lets you create very explicit code. Too much wrong abstraction comes with a cost of difficult understandability. Generics are good to some extent however they’re very open to misuse and I’ve seen this in action for years. So, I’m not in the camp of generics support in Go. However, Go team is still considering adding generics support to the language.
- About generics (kind of), there’s a great article from Shawn McGrathabout the beauty of Doom’s (the game) source code. Especially, read the part: “Minimal Templates”, I couldn’t agree more.
- Err everywhere. You need to check errors for each of the error producing function in your code explicitly. However, I love the explicitness of Go programs. In the upcoming years maybe we’d find an elegant solution for this. There are some proposals to change error handling.
- No function overloading support. However, it can be imitated to some extent by type assertions.
- Strict rules. Sometimes an advantage, sometimes a disadvantage. For example: Can feel little heavy when you have ever changing structs. However, most of these rules can be overridden by using Go’s reflection capabilities.
- Not so strong runtime safety. However, Go doesn’t bring the level of safety, for example, Rust provides. Go’s safety is for compile-time only and only to some extent for runtime (for example forbidden pointer arithmetic). So, if you’re looking also for the runtime safety, look to Rust. Go cares more about the productivity of programmers. Go = fast to production, Rust = safety in production.
- Smaller number of packages as compared to other ecosystems like Node.js and Ruby. This is because Go’s standard library is full of features which mostly doesn’t need third-party support. However, the number of packages are increasing.
—You can read the rest of the post here.
Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
https://blog.learngoprogramming.com/about-go-language-an-overview-f0bee143597c
Congratulations @inanc, you have decided to take the next big step with your first post! The Steem Network Team wishes you a great time among this awesome community.
The proven road to boost your personal success in this amazing Steem Network
Do you already know that awesome content will get great profits by following these simple steps, that have been worked out by experts?
Congratulations @inanc! You have received a personal award!
1 Year on Steemit
Click on the badge to view your Board of Honor.
Do not miss the last post from @steemitboard:
Congratulations @inanc! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!