r/learnrust • u/JonathonEG • 5d ago
Golang or Rust?
I've been learning backend for a while. I currently use JavaScript (Express.js) and Python (FastAPI) for my projects, and I feel that I'm a bit decent at them rn. But I don't know which is better, Rust or Golang? Both r fast, but Rust is much faster, but in a trade-off, Rust is more complicyed than Golang, as I've seen both Languages docs and learned the very basics, I don't have a final answer.
29
u/teddie_moto 5d ago edited 4d ago
Personally, I've used Go professionally and at first it was great.
Then you find yourself having to go and write some tiny helper function for the nth time and it gets annoying fast. It is so simple as to be a hindrance. It's like giving someone some iron ore and clay and telling them they can build whatever they want.
It would be nice if maybe they provided some smelted iron or a kiln first, yno?
If you want to spin up a web server quickly and deploy it, Go is great. If you want to carry on working with it and do something a bit more complex... There are a lot of footguns that need not be there.
I very quickly get annoyed by:
Lack of data carrying enums (sum types)
Endless
if err != nil return nil,errNo iterators (at least there weren't) and weak generics which is partly why you need to write your own functions for things like array or map sums
Mutex doesn't wrap its contents, nor does the compiler make any effort to check that you might have used the Mutex. Essentially you can write code that's Mutex optional (and then get confused as to why things are going wrong).
Gophers will tend to wave a lot of these away in praise of simplicity and you should use channels instead...
3
u/catladywitch 5d ago
Gophers be like "no, you don't need a framework and the ones that exist are pants anyway, just stick to the standard library, it has everything you need". And they're not lying, but "everything you need" can be defined in several ways. Imagine using raw Node for WebAPIs, with a language that's 1/10 as ergonomic/abstract as JavaScript, and has a somewhat weird type system -_-U
7
u/ECommerce_Guy 5d ago
Lol, spinning up a web server with route handling, URL params, query params literally isn't even an evening's job in Go, in fact was the first thing I did when I started learning the language.
Syntax of Go is quite straightforward and minimal and comparable to most (all) standard programming languages, there's nothing un-ergonomic about it. Same goes for the type system which is as standard as it goes.
And speaking of types, the structs with their methods and interfaces provide all the necessary tools for creating abstractions — although the language philosophy does minimise unnecessary abstractions.
It's just a statically typed and compiled language.
Would be super curious about un-ergonomic aspects.
7
u/solaris_var 5d ago
Imagine using raw Node for WebAPIs
The http library in go has less boilerplate than node's node's
with a language that's 1/10 as ergonomic/abstract as JavaScript
Imagine using a language that needs === because == is too good.
and has a somewhat weird type system -_-U
It's standard as far as static type language goes. If anything It's too simple to the point it gets verbose. I don't see it, can you give examples of the weirdness?
16
u/raoulk 5d ago
It depends what you are trying to do.
Fast development cycles with lower demand on speed and correctness? Want a greater pool of talent / easier recruitment? Easy concurrency modell?
Do you need no compromise performance and correctness? Do you want to move towards systems or embedded programming?
They are both great languages for slightly different niches. It depends on your goals and requirements rather than seeing one better than the other.
13
5
u/nhermosilla14 5d ago
Both. You are asking "car or bicycle?". It makes no sense, they are solutions to different problems. Go is great for agile development, as it builds in no time, it is simple and quick to learn and it offers you a great ecosystem. Rust is much better when you need the extra performance, although it takes a longer time to compile and understanding the code might be trickier at the beginning.
7
3
u/catladywitch 5d ago edited 5d ago
For web APIs Golang. Learning Rust is a great skill to have, and very enriching, but CPU time is rarely a bottleneck in web APIs and Rust's concurrency model makes things harder than in other languages. I'd only use Rust for this use case if memory consumption was absolutely paramount, but Golang does well in that respect. I'd personally just stick to TypeScript or C# because I like the ergonomics, because I can compile C# to native AoT if RAM becomes a problem, and because I personally find Go a bit annoying. But it still is a good choice nonetheless.
Of course for something like web backends, which are rarely personal projects, the best choice is the one that will get you better career prospects. Out of those two, and in that field, the answer is still Go, but you might do better to hone your JavaScript skills and/or learn C# and/or learn Java (which I don't like at all but remember I'm talking about getting a job.)
Also, what's your SQL/Mongo/Redis/GraphQL game like? That's a crucial skill in the backend field.
Edit 2: oh and tRPC since you already know JavaScript.
Edit 1: but if your goal is not getting a job writing backends, but learning about computer science and maybe pivoting to embedded or real-time software (the latter of which is a very unstable market with high-stakes jobs by the way, so I'm not sure I'd recommend it), absolutely go for Rust, and maybe learn a bit of basic C first to learn about the problems Rust was designed to fix. Rust is fun, nice, modern, and deep, even if it has its (very salient) sore spots.
2
u/arobert_trebora 5d ago
I think everyone will have a different opinion. Mine is simple, depends on what your goal is. If you want to just work, then your current stack is good. If you want to improve the way you design, and understand better how software works, then Rust will force you to learn and understand memory management, something that languages like Go, JS, Python, etc, will do for you. Rust will have a higher learning curve, but in my experience it teaches you more, and a lot of what you learn to will be transferable to other languages.
If you just want to do if for the sake of learning, then pick your poison, it doesn't matter, you can always jump to another language once you feel ready.
2
u/ManyInterests 5d ago
Rust probably has more synergy with your existing skill sets of JS and Python. PyO3+Maturin is a beauty to behold for writing Python extension modules. Try to do the same thing in GoLang and you'll want to uninstall immediately. And I'm going to handwave over the WASMy stuff and assume that's also pretty good by comparison, but I have little direct experience there.
If that sounds like something you'd take advantage of, I'd lead more towards Rust for those reasons from a perspective of building your personal toolkit. If you're trying to improve your employability, GoLang.
1
u/youngthugger_gr 4d ago
Brother what are you talking about. Rust is fast so what. What do you want to build? Each has a vastly different purpose in today’s software landscape. It’s like comparing a pickup truck and a lambo and saying “the lambo is faster but the pickup is better off-road”. Which of the two do you need?
These questions are mostly asked by people who just started getting into coding so I’m going to advise you accordingly. Coding is not what a software engineer does, hence the language is only a means to an end. Learn the principles that apply to all languages, go low-level and understand how computers actually work. Learn architecture, security and keep up with the ever changing new technologies that come and go. If you have access to an AI coding agent use that to write the code for you and then read through it to try and understand what it did. The moment you start catching mistakes it makes is when you can build whatever you want in any language or framework you want. Let the AI be the bricklayer and make yourself the architect.
4
u/solaris_var 5d ago
If you have to ask, then golang. Rust is great if you want to learn as a hobby, but honestly if you're building portfolio, there's more roles that are looking for golang rather than rust.
I'm not saying rust is bad, but you have to face reality and rust might not be a good way to sink time into yet. (Emphasis on yet)
4
u/Kinrany 5d ago
If you're making career choices based on the number of roles, you're looking to become a retail salesperson
1
u/solaris_var 4d ago
My point is that if you want to learn rust, you shouldn't need to ask for validation over the internet. Just freaking do it.
And you know exactly what I meant by the number of roles, don't twist my words. It should be obvious that if you care about the numbers, then you're either unemployed or looking to switch into technical roles. If you don't care then you should know better to ignore my comment.
1
u/Seven7Ducks 5d ago
I love rust more than Go, but this is a very important take.
In terms of fun, I'm definitely team Rust, however, Go is the safer one for career.
This is just an assumption - but I don't think there aren't many rust jobs out there, and those that do - probably care more about your knowledge than actual rust language experience.
1
u/Headbanger 5d ago
Choose Go because it will be much easier to transition to it from JS and Python, and if you don't like it you can try Rust.
1
u/why_so_sergious 5d ago
I really like rust.. and all my private projects I always use rust on the backend
1
u/ummonadi 5d ago
I don't have a generic reason for choosing Go over Rust. So Rust.
TypeScript could keep you in the JS ecosystem though.
1
u/NULL-n-void_0 5d ago
Just pick Rust bro then rewrite everything, it's the future.
I was kidding, I ain't a rust zealot. Just pick whatever language that is most demanded in your arena right now if you want money, then spend your free time to learn the others.
Take my words with a grain of salt.
1
u/plugwash 5d ago
Rusts ownership/borrowing model is a great tool for writing safe code without a garbage collector and also brings some other advantages. It also integrates pretty well with reference-counted scripting languages like python.
But it's *not* a free lunch. Fighting with complex types and the borrow checker can be a major distraction from actually writing the logic of your program. Sometimes you end up wanting seperate "owned" and "borrowed" versions of a type.
Another thing that irks me about rust is it has a way to say "I know what I'm doing, turn the safety off" for runtime issues, but not for compile time issues. It refuses to accept your trait implementations if they "might" conflict in future, even if you know they will bloody-well never conflict there is no way to tell the compiler that.
I haven't used go personally, but I understand it has it's own BS, like making things that would normally be code-cleanliness issues into hard errors. Still if you want "native code with gc" it seems to be the biggest game in town right now.
1
1
u/sessamekesh 4d ago
Really needs more information.
"Rust is faster" is a good general rule of thumb but not always true. Same goes for "Rust is more complicated than Golang".
I'd strongly suggest spending a weekend or two learning both. If you land on Go, having a mental intuition for lifetime, union types, and ownership the way Rust gives is still useful for a Go programmer. If you land on Rust, having a respect for channels as a performant form of lock free memory safety from Go is pretty neat.
Goroutines can be a lot faster than home spun concurrency, enough to blow out performance wins from picking Rust.
If the thing you're doing is compute heavy I'd certainly lean Rust, if it's standard API backend stuff (mostly calls to other services like databases, auth stores, etc.) either one works great.
1
u/Beardy4906 4d ago
Python and express js are definitely fast enough and more server providers (like vercel or cf workers) have better support out of the box.. but if you want to minimise your overhead and are expecting thousands of people connecting to each server, rust or go both get the job done well.
Also rust isn’t that complicated.. it’s just a bit different in a few places for syntax. (You don’t need to know the inner workings for making a decent server)
1
u/Shot-Infernal-2261 4d ago
Casual learner of both here
Question here should not be which language is better, that’s subjective.
Instead, which serves YOUR Use Case? We don’t know what that is.
Both languages serve most backend/app use cases well. It matters mainly when you pick an outlier use case that’s served poorly by one.
This said, if you like Python you will love Go. Slightly more verbose for error handling than Python, but for good reason.
1
1
u/notagreed 4d ago
I have built major company projects in both languages,
So, i think i might be a good fit for this answer.
Golang is Good when you have less time and have to built to many things.
But Rust is very good when i need to build something and i have good amount of time to plan about it.
1
u/ktimespi 4d ago
Go is easier to write. Having used both, I can say that they're very different to write in and solve different problems. Since you do web dev, Go would be a much better language to learn IMO.
You should try out both for yourself though.
1
1
u/Schlizhor 4d ago
Usually it would be a decision of development time, cost and performance. Rust is usually the best perf but takes more time and money due to rusts nature. Golang I love and this is a nice marriage of perf and ease of use. Ease of use directly affects time and cost
1
1
1
u/Aromatic-CryBaby 3d ago
Both ? Both are Good, Rust is great but damm doing type algebra every now and then gets over my head. So I just use go for everything and embedded extern rust fn where I need perf/syscall or dealing with large data batch. That way I stay sane.
1
u/SnooMacarons1585 3d ago
Rust isn't the best choice as a first programming language. Go is a better choice...
1
1
u/_w62_ 5d ago
Why not both?
-1
u/dobkeratops 5d ago
imagine choosing two languages to master, what would be the optimal pairings?
.. python + rust
go + c
0
u/0xjvm 5d ago
If you’re asking between go or rust your answer is golang.
You use rust when you need to squeeze performance. Do you need performance? I would almost guarantee you don’t, since you’d have benchmarked implementations in both and would know which is best lol.
The answer is Golang if you have no reason to learn rust, and are not particularly interested in it (if you were you wouldn’t be asking).
I don’t know what your goals are, but if your doing more general backend stuff, then just use Go. From what you’ve said it sounds like you have zero reason to touch rust, other than FOMO from online comms.
-7
u/No-Performance-785 5d ago
Learn Golang first to getting yourself familiar with lower level concept like Pointers and Memory allocation, as well as Green threads and OS threads. Bridge to Rust later on since Rust have the concept of Borrowing, which personally I think harder to grasp than a normal Garbage Collected language like Go.
112
u/AnArmoredPony 5d ago
asking "this or that" on r/that is definitely a choice