Live data from Hacker News

Migrating from Go to Rust

corrode.dev

451–460 of 544 posts

Re: Migrating from Go to Rust

#451

Earlier quoted context omitted.

Package management is the bane of nearly every language/technology Nobody has "solved" it, and I don't think that there will ever be one (never say never, though, right?) For Go we rely on developers of libraries to adhere to the semver versioning scheme accurately, and we cannot "pin" versions (a personal bugbear of mine) There is a couple of workarounds - using SHAs not unlike the git commit hash to provide a pseud…

> we cannot "pin" versions you can? that's why go.sum exists. you can also use the replace directive for more advanced scenarios.

No - go.sum alerts you to the change - it doesn't prevent it.

replace directives are ok, but you need to look at why workspaces were invented to get an idea of their shortcomings (hint: people used to have a replace directive locally that they would accidentally push and that would break other peoples builds)

Re: Migrating from Go to Rust

#452

Earlier quoted context omitted.

The benefit is if you lean heavily on types then successful compilation is a massive indicator in the feedback loop. Using stop hooks to ensure successful compilation after every iteration is a game changer. Go also has compilation of course but because the type system is so much more robust in Rust the compilation guarantees so much more about the behaviour of your program. You end up just code reviewing the shape a…

Code compiling is really the lowest bar of code validation, and doesn't say much of anything of the code running correctly. AI will pump out the most convoluted, over engineered, and at the same time sloppy code if you let it - and it will all compile fine.

It is of course the lowest bar. The main point is that the lowest bar in Rust is already a really a high bar compared to go lowest bar.

Re: Migrating from Go to Rust

#453
post #441

Earlier quoted context omitted.

Have you argued yourself to "it's a bad thing that the Go standard library has a cryptography library"?

Rust has clearly opined that they prefer a small standard library and a "choose your own libraries" vs "batteries included" approach. If Rust included a crypto lib and a vulnerability was discovered, many fixes are backwards incompatible. Rust maintains strict backwards compatibility, which means updating the relevant crypto functions in the std lib would necessitate a major version bump. By keeping crypto outside of…

In general, I get your argument, but cryptography is the perfect example for something so well-specified, well-understood, and extremely widely used, that these arguments do not really apply. You are not going to have to make backwards-incompatible changes to SHA256 or Poly1305, etc. It has minimal API surface too, and is not going to be a large maintenance burden. But nearly everybody is going to need crypto at some point. It is great to have blessed and well-audited standard implementations that people can rely on, without even having to make a choice. This it is not something where you want “the community to make backwards incompatible changes at a higher pace.”.

Crypto is something any modern language should include in the stdlib, imo.

Re: Migrating from Go to Rust

#454
post #385

Earlier quoted context omitted.

Rust: concat/string time: [77.801 ns 78.103 ns 78.430 ns] change: [+0.0275% +0.3169% +0.6169%] (p = 0.03 Java Benchmarks.concat string avgt 15 8.632 ± 0.105 ns/op Benchmarks.format string avgt 15 64.971 ± 1.406 ns/op Java's string concat is faster than rust's offerings.

I would be careful with this benchmark even thought it shows JIT efficiency. This is a special case which might not really reflect realworld - string was static? What if you use random string?

It is not a static string, the `param` argument gets passed in each time. I modified the above benchmark to add an int parameter in addition to the `param` argument from before. However now it's testing an itoa as well as it is dependent on the number of iterations the benchmark suite decides to run, so it is not as precise, but Java is still ahead.

Java:

    @Param({"string"})
    public String param;

    public int i = 0;

    @Benchmark
    public String concat() {
         return "prefix " + param + " " + i++ + " suffix";
     }

    Benchmark          (param)  Mode  Cnt   Score   Error  Units
    Benchmarks.concat   string  avgt   15  26.591 ± 0.242  ns/op
Rust:

    fn format2(state: &mut BenchState) -> String {
        let i = state.next_i();

        format!("prefix {} {} suffix", state.param, i)
    }


    format2                 time:   [51.923 ns 52.541 ns 53.466 ns]
    Found 10 outliers among 100 measurements (10.00%)
    4 (4.00%) high mild
    6 (6.00%) high severe

Re: Migrating from Go to Rust

#455
post #255

Earlier quoted context omitted.

C, as a language, cannot bother less about you using or not using the return values, checking them, discarding them, or using them to index an array without any bounds checking. Various linters and compilers may have their opinions, expressed as warnings, but at the end of the day it's completely up to you as a developer.

Same as in go, a language designed several decades later.

Funny - you said Go was worse - now you're saying Go's the same...

Re: Migrating from Go to Rust

#456
post #247
post #74

This is a weird document that is simultaneously trying to serve as a migration guide and an advocacy document for Rust. Ultimately, if you have to ask , the Rust vs. Go consideration boils down almost completely to "do you want a managed runtime or not". A generation of Rust programmers has convinced itself that "managed runtime" is bad, that not having one is an important feature. But that's obviously false: there a…

It feels like you’re upset because your favorite language has objective flaws that people are pointing out. You’re also trying to minimize people’s lived experiences and pleading with them to stop pointing the flaws out. Sure, Go is better than Python in some things. But developers deserve the best. We deserve not to have to deal with Go’s quirks, idiosyncrasies and design mistakes.

> We deserve not to have to deal with […] quirks, idiosyncrasies and design mistakes.

True but unrealistic. Every language has warts, including Rust.

Re: Migrating from Go to Rust

#458
post #255

Earlier quoted context omitted.

Same as in go, a language designed several decades later.

Funny - you said Go was worse - now you're saying Go's the same...

It is worse, gcc has the warnings at least, go does not. You need a 3rd party linter.

Re: Migrating from Go to Rust

#460
post #283

Earlier quoted context omitted.

It's the same logic for human and for AI code: In Rust the compiler catches many bugs so you don't have to. If the LLM gives you safe code you know there are entire classes of things you don't have to review for. That said, I agree with you. My experience is that LLMs are great if you are highly competent in the domain in which you let them work. And it's probably easier to be competent in Go than in Rust.

I found it's the opposite. Thanks to LLM's whole classes of problems otherwise solved by using Rust are gone. It's now more important that the generated code is easy to read.

Relative to Go? I'm pretty sure your Go code won't be faster if you used LLMs. If you need that, Rust is still preferred.

Relative to C/C++? That'll be very interesting. Do you have some evidence that LLMs can create memory-safe code in C/C++? It'll be truly amazing if true, but given that they apparently struggle to create/maintain big codebases in already-memory-safe languages I seriously doubt it.

Post reply on HN