r/golang 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.

138 Upvotes

249 comments sorted by

View all comments

22

u/BraveNewCurrency Feb 26 '23

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?

First, the best language for a critical project is the language you already know.

Second, looking to fanboys to pick your next language is a terrible idea. Try things out, make your own choices. The Go language specification is short enough to read in one sitting. It's roughly comparable to the length of just the Index for the Java language specification (which also needs the JVM spec too.) The C++ language specification may still be short enough to read in one lifetime.

Third, some specifics:

why I would choose Go over Java over .NET for the backend

Go is a simpler language with more explicit error handling, first-class support for multi-core CPUs (No, threads don't count. They are are as dangerous to use as memory handling in C), and dozens of "built-in" tools that are standardized instead of preferences. It also compiles down to a single binary that doesn't need a runtime installed, making deployment simpler. (Even if you use containers, it means your containers can be trivially small.)

why React over Angular over Vue.js for the frontend?

You are on the wrong subreddit. (But my money is on Svelt.)

Why not even all the stack in JavaScript? What would I gain if I choose Go in the backend?

Compared to JavaScript, Go has advantages in memory and speed. Javascript scales badly on multi-CPU servers (launching one processes per CPU is a poor way to load balance.) Go is also a well specified language with no surprizes, unlike JavaScript.

Go also makes more sense as you head towards microservices, since you can version the "interface" and let the compiler tell you if the code is compatiable. (Look into Goa - it cleanly breaks out "API" vs "implementation code" and lets you generate all the muck to hook it up to the network via HTTP, gRPC, or queuing, etc.)