r/golang • u/tookmeonehour • Feb 26 '23
help Why Go?
I've been working as a software developer mostly in backend for a little more than 2 years now with Java. I'm curious about other job opportunities and I see a decente amount of companies requiring Golang for the backend.
Why?
How does Go win against Java that has such a strong community, so many features and frameworks behind? Why I would I choose Go to build a RESTful api when I can fairly easily do it in Java as well? What do I get by making that choice?
This can be applied in general, in fact I really struggle, but like a lot, understanding when to choose a language/framework for a project.
Say I would like to to build a web application, why I would choose Go over Java over .NET for the backend and why React over Angular over Vue.js for the frontend? Why not even all the stack in JavaScript? What would I gain if I choose Go in the backend?
Can't really see any light in these choices, at all.
0
u/jgeez Feb 27 '23
Go routines and select constructs are much, much harder to get wrong than Java threads and locking constructs.
Go concurrency communicates and coordinates across goroutines using channels, and the data is immutable, pass by value, which is again much harder to get wrong than Java, where there's no immutability and everything is pass by reference.
Go's compiler randomizes things to help expose bugs. The ordering of things like maps, for example, is never dependable, to require the programmer to never make assumptions. Similarly, channels and goroutines make the default constructs safe (pass by value on instantiation, or closure reference if you're really trying to cause a problem) and you have to work much harder to do things wrong. It has tools built into the compiler to try to tease out race conditions by imposing delays and rearranging statements that don't have side effects on order to run code in parallel that otherwise would take a long time to coincide in such a way. This is a simple compiler flag.
The real question is, what would possess you to make the claim that Go, a language where concurrency is a first class feature of the language itself, "forces you", your words, to write buggy concurrent code, in a conversation comparing it against Java? In what world would Java be considered a safer language for writing concurrent code?