Hello everyone, I'm back. The past few days were crazy at my work, so many complicated tasks needed to get shipped and I couldn't write here.
Today I'm coming up with a different topic: I don't get the point of Golang - and I need help with it.
Contextualizing things up
Since the beginning of my career, I've always used node in most of my projects, from discord bots to complex backends. I feel a little comfortable with it, but I realized that my way of thinking is becoming tied to this technology.
So, I need fresh air and new things. That's why I want to give Go a chance.
Okay, I get it – when compared to other languages, Go is known for its simplicity and the plethora of benefits it offers. But I don't want to fall into a trap that will solve Go-specific use cases tasks but with a Node mind.
I also don't get the point of it (as the title says). What different or specific things *need * to be done in Go that I can't do with Node?
I want to invite more experienced people, people who have been on the two sides, people who are learning one of these two amazing techs, to join start a discussion here with a main question:
What can I do with Go that I can't do with Node?
Feel free to join in the comments:
Top comments (14)
I would also like to hear a perspective from other experts there, even though I understand the obvious benefit to using GO, that its a compiled language rather than interpreted at runtime, which makes it faster
I think you are asking the wrong question.
You said you need fresh air, then maybe the question is why do you need fresh air?
I always try new languages, listen to talks that go over my head. But i consider that a part of my developer life. Always wanting to learn how to do better, and failing a lot along the way.
I would suggest you focus on something you see in another language you want to understand. And once you understand it, try to do it in your language of choice. All languages are evolving and a thing that wasn't possible a year ago, can be possible now.
I use now Go for most of my projects. When I started, I was wondering why I shouldn't just use Python. After a while, something just clicked, and now I love it.
Nothing needs to be done in Go, so if you'd rather, you can something else.
What can you do with Go but not Node?
go.mod
is complex, but once you get the hang of it, it's an absolute pleasure.node_modules
directories, you have one~/go
directory that holds all of your dependencies, and you can use them across different projects.Side note: The creator of Node switched to Go. Then Rust. Then made Deno.
Hope it helps :)
I haven't used Node.js for much more than playing around. But I do now have some more serious Golang projects behind me and so I can give you my reasons for liking it. I'm a Lisper at heart so Go is not my dream language, but it sufficiently embodies the Unix philosophy of simplicity and readability that I can't not like it. Here are some points I find noteworthy:
I find go a breeze to write and the added performance and goroutines is great. The code structure is much more easy to reason about. Pass by value or pointer, your choice. Especially when seeking performance, one or the other could better as per stack vs. heap allocation. Gives you control to some degree of how you manage the life cycle of your variables.
I also love how they've implemented interfaces: you can only define methods, everything else is up to you how you need to implement it, no need for further strictness. Testing comes out of the box and it works great, no need for 3rd party tools.
Tooling is great, fmt, and everything comes with a strict set of rules that makes it easier to avoid some pitfals. Also, go finally has go.mod, without which go was a bit messy for me module wise, but not the case anymore.
Also, true type safety! Not just a fancy "linter" that does not actually provide safety.
Any project I start now I go with go out of the box. Only might use echo as a basic framework for web servers, as I feel it saves you a bit of time.
I feel I write code faster, with less hassle, and have everything out of the box right there. Compiles fast too.
multi threaded server that runs requests in parallel with minimal resources without an interpreter. You can't have it on python due to GIL, you can't have it on node due to C++ single event loop
if all you do is CRUD, it doesn't matter for you but when it comes to deployment you will be dealing with process managers/spawners or web server gateway interfaces/workers to be able to glue-jail your interpreter. In some cases, you can get away with [ python main.py] or [node index.js] entrypoint docker container but it is not ideal for prod
In go/rust/zig, you just ship native binary in a scratch container and it just works because it is native static single bin kinda like C but with less cumbersome tooling
lastly, I think working without type hinting doesn't scale in team projects, it is easily the Achilles heel of duck typed languages
From the point of view of an application developer you can do pretty much the same things with Node as you can with Go.
So, the change is not worth if Node fit perfectly your application scope.
Even if you use Node successful, you might face some issues while hitting certain limits.
For example, if you write an application that is doing a lot of I/O processing, or you use a huge amount of RAM memory, just to highlight some cases that pop up in my mind.
With Go, you will have a much efficient language, that can help you work on multiple threads, using all the power of modern multi-core CPUs.
Your code in Node can't do that, you need a library in C++ or Rust, that handle the computation for you, or write your code to have different Workers, but this is not as efficient as the Go solution.
With Go you can build executable for many architecture, you just need to provide the target and it will cross-compile.
With Node, you may don't have the issue, if you don't have binary dependencies, but if you end with one of those, you have to set up a build chain that include this target architecture, I mean, you need a VM or a Container Image of this platform to build your application and deploy it.
The list can be longher, but you may get it, there are reason you may choose Go for your task, because with Node you can't be so effective.
In any case, I suggest you to learn Go a bit, even you don't end up using it with your production apps.
Why, because it will help you to refresh your mind with an outside the box approach.
It's good to pich a different language, just for learning purpose, time by time.
After having used TypeScript for like forever, writing Go feels like a huge step back in language ergonomics. Some of it because I'm more experienced in TS, some because TS really does have a lot more going for it with things like map().filter().reduce() etc. Let's not talk about error handling. That being said, it's good to be curious and Go does have it's place, which is why I still use it for certain tasks like where I want a single static cross-platform binary.
I always find the error handling argument weird. What do you guys do with your errors? I'm all for optimistic programming, but I've worked on so many projects where you have no luxury of just bubbling your errors up top, as in the end you'll end up having to still write a nasty block of code to actually handle those errors. I feel being explicit with every error just makes it easier to debug.
I think there is no "point" for Go. Several languages are used for building complex backend applications. For me node.js is like a bridge to the other side. If someone is used to frameworks, JS and TS its a small hopp to node.js without struggling with new languages like Go, Rust, Kotlin, ...
Go's concurrency and the channels to communicate and synchronize them are similar to the event driven non-blocking model from node.js. Go concurrency might be on heavy cpu-intensive operations slightly better...
So my answer to Your question is : Nothing
Go is not an exciting language in terms of syntactic sugars. Its very (deliberately) boring in that respect.
Go is like the ultimate grug-brain language. It appeals to me at least because the language makes it harder for someone to make a clever and incomprehensible solution to an algorithm. In Go one is strongly inclined (both in terms of the language and the community around it) to do it in a plain way.
The hopeful upshot is that I will actually be able to understand what the hell I and my coworkers were thinking 6 months down the line.
Listen to Rob himself on the subject: https://www.youtube.com/watch?v=PAAkCSZUG1c&t=14m35s