DEV Community

loading...
Cover image for 5 reasons to use Golang

Why use Golang 5 reasons to use Golang

carloslfu profile image Carlos Galarza ・2 min read

There are several reasons to start using Go:

  1. It’s statically, strongly typed with a great way to handle errors, this makes Golang more reliable and robust.
  2. It compiles down to one binary. Just execute it in wherever you want.
  3. It’s faster.
  4. The main reason why I use it is simplicity, there is only one way to do things, no more “beauty” and “clever code”, this point increases your code readability. You and your team always know what a piece of code is doing. It is the Golangs killer-feature 🔥.
  5. For the reasons above, it is easier to teach Golang to new devs from scratch and they will get productive in a short time.

In my case, I used NodeJS for a long time and had Golang under my eyes once I read an article by Tj, an important member of the NodeJS community. If you have used Node, probably you have used ExpressJS or at least read about it. Well, TJ Holowaychuk is its creator! I leave here the link to the article: https://medium.com/code-adventures/farewell-node-js-4ba9e7f3e52b

In the beginning, Golang is a bit weird and your code gets larger, you have to forget about Array.map .. filter .. and all kinds of “beauty” things of JavaScript and other modern languages, also, you have to handle every possible error. But, in the long-term, it makes your code more readable, simple and stable.

For example, the unique way to iterate in Golang is “for” and there is no ternary operator 😮, but this is the Golang strength 💪, simplicity.

A couple of months ago with my team, we are using Golang for building the LiciMatic’s backend, the platform I work on, and now Golang is my preferred language.

So, I recommend you learning Glango, you are going to learn a lot and you will have big professional opportunities.

I want to highlight that Golang is at the top of the best-paid languages of 2019: https://lvivity.com/top-highly-paid-programming-languages

I leave here 3 free learning resources:

Want to learn more about Golang and other interesting tech topics?
Follow me here on Dev.to and on Twitter: https://twitter.com/carloslfu

Thanks and happy learning! 🙂

Discussion

pic
Editor guide
Collapse
curtisfenner profile image
Curtis Fenner

While Go is statically typed, I would not call it "strongly typed". It has one of the weakest type systems among popular statically typed languages.

It doesn't have real enums (you can merely name some integer values); it certainly doesn't have sum/tagged union types; it doesn't have generic/parameterized types or functions; its subtyping is only structural; everything can be null/freely "zero initialized".

These all eventually become impediments to designing obviously correct software that is verified by the typechecker.

Collapse
crabmusket profile image
Daniel Buckmaster

"Strong" and "weak" typing aren't very well-defined terms, but according to most of the definitions on this page Go should probably count on the strong side. Go doesn't allow many implicit conversions, doesn't treat pointers as integers, doesn't have untagged unions AFAIK, and performs most type-checking at compile time, though using interface{} and reflection you can mess around with it.

Collapse
yujiri8 profile image
Ryan Westlund

Eh... I heavily disagree. Those map and filter things are extremely powerful, and there is no way code is more readable without them.

Imagine a language where you can't define functions. It's more readable, its advocates tell you, because it forces you to give up all that beauty and clever code you can write when you can encapsulate and reuse functions.

That's what this argument sounds like to me, because there are some operations that just can't be encapsulated into reusable functions (though I hear they're adding generics in Go 2 which will enable map and filter and a host of other useful things that are impossible as of now).

But I think the error handling is an even bigger deal, for several reasons:

  1. It's verbose, which reduces readability.

  2. It's dangerous. In Go, if you don't handle an error properly, you get the default behavior of silently ignoring errors. In exception languages, the default behavior on an error is to crash, so you find out about it.

Edit: accidentally posted this before it was done, will update

Collapse
yujiri8 profile image
Ryan Westlund

3: errors carry almost no useful information by default. You don't get stack traces on normal errors, only the root error message. You don't even get context messages unless you out of your way with a package like github.com/pkg/errors.

4: It breaks composability, since the error return is a separate return slot, so you can't directly feed a function that might fail into another.

5: It doesn't play well with defer, since any error from a deferred call is ignored.

Have you used any languages with monadic error handling? I think Rust is a great example of this done better. In Rust, functions that can fail return a Result, which is a sum type that can either be Ok (and contain a value of another type) or Err (and contain an error).

Compared to Go, Rust also makes all points of failure visible, but has several benefits:

  • It's much less verbose, since there's a syntactic sugar to take a Result and return it if it's an Err but continue on with the unwrapped value if it's an Ok. It's like exception behavior, but you have to opt into it, so you still see all the points of failure and a function's type signature still indicates whether it can fail.

  • It's safer, since the compiler is able to guarantee that all errors are handled appropriately.

  • It doesn't break the composability of functions.

Rust is also very performant, and has a much more powerful type system (including full sum types and parameterized types with trait bounds) that allows reusing code much more effectively than you can do in Go - without sacrificing the benefits of static typing (like Go does if you use interface{}).

Collapse
carloslfu profile image
Carlos Galarza Author

Those are good points! Thank you. I agree those are pain points. I think monadic error handling is far better than exceptions and the Go way. Also, I agree that Go 2 is going to be better because of generics.

That said, I still like Golang's simplicity. I agree Rust is excellent, but Go is less difficult to learn, and that is sometimes better than being perfect. When choosing a language, you have to make tradeoffs. For instance, if you have NodeJS devs and you have to develop a CPU intensive web service or optimize an existing one. Golang is an excellent choice over Rust because it is going to be easier to learn and good enough for the task.

Collapse
antoniocs profile image
AntonioCS

I want to highlight that Golang is at the top of the best-paid languages of 2019: lvivity.com/top-highly-paid-progra...

You should have started with this one and then added concurrency.
All your points would benefit from good examples.

Collapse
uptechteam profile image
Uptech

It's been a while since the developer community got excited over a new programming language.
But you should remember Go is handy when it’s used for addressing bottleneck issues in processing time. uptech.team/blog/why-use-golang-fo... - More about why use golang for projects here

Collapse
bskiefer profile image
Collapse
sykora_b profile image
Alan B. Sykora

Go shows the awesome performance when creating the backend of the web apps. As for disadvantages, it lacks an embedded troubleshooting tool. I've read an article on this topic, check it out here.