Top
Best
New

Posted by jabits 1 day ago

Migrating from Go to Rust(corrode.dev)
421 points | 425 commentspage 4
hasyimibhar 22 hours ago|
It is also easier to make your code deterministic with Rust vs with Go, which is incredibly useful if you need to perform deterministic simulation testing + property-based testing. I recently wrote a Postgres-to-Iceberg data mirroring tool [1] in Go, but I ported it to Rust because I wanted the ability perform DST without fighting Go's runtime [2]. But if the domain is not critical that warrants DST, I would still pick Go over Rust any day.

[1] https://github.com/polynya-dev/pg2iceberg

[2] https://www.polarsignals.com/blog/posts/2024/05/28/mostly-ds...

3uler 10 hours ago||
Golang is an amazing runtime with a bad language, one that conflates simple with easy. I view it the same way I view Java: a fine choice for a corporation, but nothing to love. Although Java’s gotten a lot better lately.
DeathArrow 10 hours ago|
For me having the proper tool for the job trumps loving. I don't have to love the language, I have to love the process and the end result.
bnolsen 8 hours ago||
I would think that you might have a better time going from go to zig. You would have to provide a pattern for implementing the interface model go uses.
MeetingsBrowser 8 hours ago|
What are the benefits of moving from Go to Zig?

It seems like you lose a lot (automatic memory safety, simple language, easy concurrency) and gain very little.

nirui 15 hours ago||
> It confuses easiness with simplicity

A lot of libs/packages in Go's stdlib also has this problem. They like to package everything in a very tight interface (very obvious example includes crypto/* and http), without exposing implementation detail to the end user.

Doing this of course has it's benefits, but if the feature provided by the stdlib slightly don't fit you needs, then you might have to write your own (potentially unsafe and/or less performant) one from zero.

Rust is great overall, but there's some oddities. For example their lib.rs / `mod` is very, very unintuitive, it felt overdesigned and unnecessarily complex (just see [their book]). I like what Go or Java did to their lib/package systems, it's much better that way.

[their book]: https://doc.rust-lang.org/stable/book/ch07-05-separating-mod...

magicalhippo 15 hours ago|
I've come to hate hiding internals. Put them in a namespace which makes it clear there's no API stability guarantees, but make them available if needed.

As you note it's just pain with no gain to properly hide them. Users can't readily work around bugs or extend functionality.

netheril96 18 hours ago||
I've swinged between Go and Rust for my personal projects multiple times. For work, it is decided by the management so not my problem.

The biggest gripe I have with Go is the lack of *any* compile time check for mutex. Even C++ has extensions like ABSL_GUARDED_BY. For a language so proud on concurrency, it is strange not to have any guardrails.

ted_dunning 18 hours ago|
The guardrails are channels.

If you have a mutex on a structure, linters such as are packaged into Goland will catch oversights quite effectively.

If you are using fancier concurrency structures, you should consider channels instead.

netheril96 17 hours ago||
Channels are not for everything. Plenty of mutex cases cannot be rewritten as channels, or will be very unwieldy so. In fact, every large Go project I have seen uses mutex here or there.
kune 14 hours ago||
Theoretically you can use channels to simulate a mutex, but I agree with you there are use cases where a mutex makes more sense. They are even used in the standard library, for instance to implement sync.Once.

But generally I would agree that if you need to code parallel execution, channels are a good way to do it, because you can avoid race conditions if you share data only over channels. The biggest problem is that a lot of people don't understand, that channels with a buffer larger than 1 are a sign of problems in the architecture.

There is a type of parallel programming with workers for specific functions, that always leads to performance issues. The problem is you need to right-guess the distribution of work, when you have to define the amount of workers for a specific function. At least one go routine for one request is a much better approach than function-specific workers.

AtNightWeCode 5 hours ago||
Anybody who actually moved a set of services from Go to Rust? I've heard that in practice Rust uses more memory than Go for web services. When I ask LLMs I get the same answer as in the article. A 30-50% reduction but then also claims on how much memory Go uses. Which is about 5-10x more than our average service use.
0xfurai 23 hours ago||
The "when to enforce it" framing is what sticks with me. Go and Rust agree on safety, concurrency, simple deployment, but Go says "catch it in review" and Rust says "catch it before it compiles." The right answer depends entirely on how expensive a production incident is for you vs. how expensive slower iteration is.
euroderf 17 hours ago||
And TLA+ and Lean say "catch it before you write any code".
LtWorf 23 hours ago||
> but Go says "catch it in review"

So, in production?

airstrike 23 hours ago||
It's AI slop, it makes no sense
amelius 23 hours ago||
Go has shorter and more predictable GC pauses. If a reference count drops to zero in Rust, it may take an unbounded time to free all the things it refers to (recursively if necessary).
cube00 18 hours ago||
I still prefer having deterministic control over when the free occurs.

For example, I can transmit the response to the client and then free the memory afterwards so they're not kept waiting.

amelius 10 hours ago||||
Can't use that approach for a GUI.
za3faran 6 hours ago|||
What if you have many clients that are constantly coming in, when do you decide to free the memory after sending their respective responses?
HackerThemAll 11 hours ago|
The datetime to string conversions in Go are devil's spawn.
kermatt 4 hours ago|
Share some examples?
More comments...