News for hackers. Stuff that matters.
Re:Using Rust at a Startup: A Cautionary Tale by candiddevmike on Tuesday November 22, 2022 @09:22PM (#33714349)
God I get tired of the if err criticism with Go. I truthfully don't even notice it when I write Go, I don't understand why folks get so bent out of shape over it.
Re:Using Rust at a Startup: A Cautionary Tale by deagle50 on Tuesday November 22, 2022 @09:32PM (#33714432)
It's super annoying, I switched from Go to Rust for my personal projects because of it. It's like a seat belt beep that won't stop.
Re:Using Rust at a Startup: A Cautionary Tale by satvikpendem on Tuesday November 22, 2022 @09:25PM (#33714374)
Your profile link doesn't work. Regarding `if err`, it's one thing to add it everywhere, it's another to forget and then have something break. If Go also checked for exhaustive error handling, I wouldn't mind it either.
Re:Using Rust at a Startup: A Cautionary Tale by Zagill on Tuesday November 22, 2022 @09:28PM (#33714404)
This is pretty trivial to accomplish with linters. Where I work your build will fail if you have unchecked err's hanging around, along with a lot of other sorts of issues. No, it's not built into the language by default or anything, but is that dealbreaking?
Re:Using Rust at a Startup: A Cautionary Tale by satvikpendem on Tuesday November 22, 2022 @09:31PM (#33714426)
It is dealbreaking. These days I gravitate more and more towards strongly statically typed languages over weakly dynamically typed ones, which I definitely used to use when younger. Fact is, linters are simply not the same as something built-in from the ground up. Trust me, I have written many thousands of lines of Python and Ruby, and even with linters, they don't hold a candle to even something like TypeScript in terms of type ergonomics and refactorability, not to mention even stronger languages like Haskell or OCaml.

Anecdotally this is the same argument many C++ devs make in regards to Rust safety guarantees. The difference is just...different.

Re:Using Rust at a Startup: A Cautionary Tale by pipe_connector on Tuesday November 22, 2022 @09:37PM (#33714463)
In general I agree with you, but Go's simple syntax means that there are extremely few (if any? I've never run into one) edge cases with checking that an error was at least considered. The guarantees are the same as what you get with e.g. Rust. The only difference is that you have to run a third party's code, which I don't like, either.
Re:Using Rust at a Startup: A Cautionary Tale by satvikpendem on Wednesday November 23, 2022 @12:45PM (#33722257)
> The guarantees are the same as what you get with e.g. Rust.

I'm not sure how they could be, given that Rust checks exhaustively and Go doesn't. If one programmer messes up, then that's it, an unhandled exception might occur in the future. I would rather rely on the computer telling me when it should be handled over humans.

Re:Using Rust at a Startup: A Cautionary Tale by kika on Thursday November 24, 2022 @08:57AM (#33731316)
And the worst human to tell you that is an SRE
Re:Using Rust at a Startup: A Cautionary Tale by Zagill on Tuesday November 22, 2022 @09:37PM (#33714469)
Well for one, Go is not a weakly, dynamically typed language, and this also isn't an issue of type checking at all.
Re:Using Rust at a Startup: A Cautionary Tale by satvikpendem on Tuesday November 22, 2022 @09:42PM (#33714497)
Sure, I did not mean Go specifically when I said that, just stating how when I used linters in other such languages, it was not comprehensive enough to replace a language with types and other niceties built-in.

I also don't use much Go because it lacks good algebraic data type support, honestly can't imagine going back to a language that doesn't have them as I like to define all my business logic in types and then build the actual application from there. Go simply doesn't have that capability.

Re:Using Rust at a Startup: A Cautionary Tale by Zagill on Tuesday November 22, 2022 @09:55PM (#33714585)
I'm not familiar with algebraic data types, what's missing from Go that makes that impossible? Sounds about like defining structs/other custom types before writing any method bodies, which is what I'd typically do in a Go project.
Re:Using Rust at a Startup: A Cautionary Tale by satvikpendem on Tuesday November 22, 2022 @09:59PM (#33714607)
> what's missing from Go that makes that impossible?

The language maintainers don't want to add it: https://github.com/golang/go/issues/19412

Re:Using Rust at a Startup: A Cautionary Tale by pipe_connector on Tuesday November 22, 2022 @09:31PM (#33714430)
https://github.com/kisielk/errcheck

Every Go project I've worked on has used this linter. I think it should be builtin, but it's very easy to incorporate.

Re:Using Rust at a Startup: A Cautionary Tale by shepherdjerred on Wednesday November 23, 2022 @01:31AM (#33715916)
> but it's very easy to incorporate.

As someone who is adding this to a Go project with hundreds of unchecked errors, I disagree.

Re:Using Rust at a Startup: A Cautionary Tale by styluss on Wednesday November 23, 2022 @09:50AM (#33719775)
What kind of error does it check?
Re:Using Rust at a Startup: A Cautionary Tale by panachaud on Friday November 25, 2022 @05:26PM (#33747496)
It looks for code where the err != nil hasn’t been handled
Re:Using Rust at a Startup: A Cautionary Tale by thayne on Tuesday November 22, 2022 @11:41PM (#33715282)
That just means you have written a lot of go. I truthfully don't notice lifetimes or the borrow checker most of the time when I write rust.

I actually think that, ironically, the if err problem with go is worse for reading code than writing code. If you are used to the pattern it's not that difficult to add the `if err != nil` after a fallible function call, and as is mentioned elsewhere, linters can help catch if you miss it. However, if you are trying to figure out what a function is doing, it can be very difficult to follow the flow, when 3/4 of the code is

    if err != null {
        return err
    }
especially if you don't have a lot of experience reading go code. And that 3/4 is not an exaggeration. I have had to read functions where literally every line of normal logic is followed by those three lines to propagate the error from the other function. A function that would otherwise fit on a single screen now takes up over three screens worth of scrolling.
Re:Using Rust at a Startup: A Cautionary Tale by derangedHorse on Tuesday November 22, 2022 @11:54PM (#33715380)
I don't see how that's a specific problem of the Go programming language though. Rust still has option types and the cases where an Option could be None still need to be handled. Maybe the big difference is the compiler forcing the handling of this case but it seems like a small thing for experienced programmers.

Rust's default paradigm for memory management seems more significant of a language feature in my opinion and is what I can imagine most people don't like. A lot of the programs I write don't fall into the class of problems Rust is trying to prevent which makes the restrictions it enforces bothersome for me.

Re:Using Rust at a Startup: A Cautionary Tale by thayne on Wednesday November 23, 2022 @12:06AM (#33715457)
> Rust still has option types and the cases where an Option could be None still need to be handled

And rust has the `?` operator, as well as combinators like `map`, `and_then`, `unwrap_or_else`, etc. which IMO make the flow much easier to follow than say `if option.is_none() { return None }`.

> Rust's default paradigm for memory management seems more significant of a language feature in my opinion and is what I can imagine most people don't like

I never said it wasn't. My point is that if you use a language enough you get used to things that are difficult for people less experienced with that language.

Re:Using Rust at a Startup: A Cautionary Tale by tptacek on Wednesday November 23, 2022 @12:17AM (#33715511)
`map` and its cousins make Rust error handling code easier to write. It doesn't make error handling easier to follow. And Rust introduces the problem of "thicket of different error types". And that's before we get to the sync/async boundary. There's a lot not to like about both Rust and Go's error handling. People need to stop pretending that either language has this answered perfectly.

People complain about Go's wordy error handling, but systems programming is error programming. The places where Go's error handling is most annoying is in application code, where you'd ordinarily EAFP instead of LBYL. But that's also the code Rust is least convenient for.

Go vs. Rust is truly the dumbest programming language slapfight in the entire industry.

Re:Using Rust at a Startup: A Cautionary Tale by thayne on Wednesday November 23, 2022 @12:48AM (#33715691)
Having used exceptions, like in java and python, checking error return values like in go and to some extent c, and using ADTs to represent error conditions like in rust, haskell, and scala (scala has exceptions too, but it's arguably more idiomatic to use Option, Try, etc.), primarily in application code, I by far prefer using ADTs. IMO it is a good balance between explicitness and verbosity. And ensuring you handle errors is built in to the type system.
Re:Using Rust at a Startup: A Cautionary Tale by 3a2d29 on Wednesday November 23, 2022 @01:48AM (#33715993)
I feel like the err != nil issue combines with GO using initialization to 0 values to be annoying.

If you forget err != nil, well your value does actually have a value and you would think your result was 0.

Re:Using Rust at a Startup: A Cautionary Tale by Aeolun on Wednesday November 23, 2022 @04:31AM (#33716998)
I dunno, if my exceptions would have to be manually rethrown every time, I’d get really cranky very quickly.

I don’t think that’s any better in Rust though.

Re:Using Rust at a Startup: A Cautionary Tale by ColonelPhantom on Wednesday November 23, 2022 @05:54AM (#33717611)
Rust has many convenient shorthands like the ? operator, where `let x = foo()?` is equivalent to

  let x = match foo() {
      Ok(value) -> value,
      Err(e) -> return Err(e),
  }
Re:Using Rust at a Startup: A Cautionary Tale by cesarb on Wednesday November 23, 2022 @08:21AM (#33718792)
IIRC, `let x = foo()?` is actually equivalent to

  let x = match foo() {
      Ok(value) -> value,
      Err(e) -> return Err(e.into()),
  }
Which can automatically convert one error type into another when the appropriate From and/or Into impls exist.
Re:Using Rust at a Startup: A Cautionary Tale by steveklabnik on Wednesday November 23, 2022 @10:22AM (#33720269)
It is a little more complex than that these days

https://github.com/rust-lang/rust/blob/4e0d0d757e2f1b61ec809...

Re:Using Rust at a Startup: A Cautionary Tale by rob74 on Wednesday November 23, 2022 @03:51PM (#33724363)
Many convenient shorthands that you all have to be familiar with before being able to write (and read) Rust competently. I guess that's what they mean with the steep learning curve...
Re:Using Rust at a Startup: A Cautionary Tale by bpicolo on Wednesday November 23, 2022 @05:45PM (#33725487)
If anything, context param drilling due to lack of thread local variable or similar is way less ergonomic
Re:Using Rust at a Startup: A Cautionary Tale by caladin on Thursday November 24, 2022 @02:51AM (#33728783)
This reminds me of the same response regarding generics from Go users:

> God I get tired of the generics criticism with Go. I truthfully don't even notice it when I write Go, I don't understand why folks get so bent out of shape over it.

Over ten years later, Go gets generics.

Re:Using Rust at a Startup: A Cautionary Tale by foldr on Thursday November 24, 2022 @03:00AM (#33728832)
There’s no contradiction there. I rarely missed generics in Go. Now on the rare occasion that they add significant value, I can use them.
Re:Using Rust at a Startup: A Cautionary Tale by lenkite on Thursday November 24, 2022 @04:01AM (#33729146)
It's hard catching bugs in go when your eyes tend to glaze over tens of thousands of 'if err != nil' statements causing bad signal-to-noise ratio.

I actually like Go over Rust, but really, really wish the language provided some more ergonomics and fixed several of its terrible gotchas. (the for loop issue for example)

Also wish Go gets RAII some day.