Live data from Hacker News

Ergonomic errors in Rust: write fast, debug with ease, handle precisely

gmcgoldr.github.io

11–20 of 28 posts

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#11
post #9

Earlier quoted context omitted.

Cognitive load is more expensive than compilation time.

Compilation time turns into cognitive load via frustration. Death by a thousand cuts.

How long are your compiles? The longest I’ve ever seen is a massive Bevy project with 700 dependencies, and it still compiled in <5min from an empty cache, and then 2-3 second incremental builds (mostly link time).

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#12

I have never seen anything use Result , that is such an anti-rust thing to start with.

LLMs love to do this. I assume they are trying to write JavaScript or Python or whatever, but in Rust.

I have never seen an actual Rist programmer do this, and that was clue #1 that TFA was AI generated without review.

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#13
post #9

Earlier quoted context omitted.

Cognitive load is more expensive than compilation time.

Compilation time turns into cognitive load via frustration. Death by a thousand cuts.

https://xkcd.com/303/

(compilation time is good for brain switch off time - i.e. reducing cognitive load).

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#14
post #4

This just feels like recreating exceptions, but with more complicated syntax.

I mean broadly that's my entire problem with errors as values: every implementation wastes a ton of syntax trying to make them like exceptions.

The common problems with exceptions isn’t the easy part of try/catch, it’s the execution model and “any function could throw” that causes most contention. Error values are logically simpler and fully document if and what errors the function can return. Checked exceptions solve that too, but in practice nobody used them even where available. And you still end up with hidden control flow with exceptions, the exceptional path through a function is syntactically invisible and difficult to audit without very strong language tooling.

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#15

I have never seen anything use Result , that is such an anti-rust thing to start with.

LLMs love to do this. I assume they are trying to write JavaScript or Python or whatever, but in Rust. I have never seen an actual Rist programmer do this, and that was clue #1 that TFA was AI generated without review.

I do when prototyping. Long term you don't really want to pass around &str errors, but they are quick and dirty and easy to get rolling with.

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#16
post #5

How is this different from the even more ergonomic “#[from]” provided by thiserror?

Are all of these proc macros worth it? The compile times for proc macros explode. I'd rather hand-roll errors than deal with more proc macros. Or better yet, have code gen pay the cost once and never deal with it again.

Frankly, std::io:Error::other is good enough most of the time.

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#18

This just feels like recreating exceptions, but with more complicated syntax.

Sometimes it’s nice to have one control flow mechanism rather than too. One could argue that traditional exceptions are more complicated with a their alternative control flow and syntax.

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#19

Rust used to be pretty hard to read and write, now with ai coding agent not anymore.

Have you had success doing non-trivial Rust with AI agents? In my experience they're all pretty bad at it once you get beyond the basics and start having tricky lifetimes and complicated types, but I'm interested to hear what people have done to make it better.

Re: Ergonomic errors in Rust: write fast, debug with ease, handle precisely

#20
post #4

Earlier quoted context omitted.

I mean broadly that's my entire problem with errors as values: every implementation wastes a ton of syntax trying to make them like exceptions.

The common problems with exceptions isn’t the easy part of try/catch, it’s the execution model and “any function could throw” that causes most contention. Error values are logically simpler and fully document if and what errors the function can return. Checked exceptions solve that too, but in practice nobody used them even where available. And you still end up with hidden control flow with exceptions, the exceptiona…

And also the issue with checked exceptions is that one can't be generic over the checked exception, at least in Java. So it's impossible to write out a universally useful function type that's strictly typed on the error. This definition of `ThrowingFunction` for Java [1] needs just have `throws Exception`, allowing just about anything to be thrown.

Most functional-inspired languages would just have a single `f: T -> Result` interface, which supports both (1) a specific error type `E`, which can also be an uninhabited type (e.g. never type) for an infallible operation, and (2) where `U` can be the unit type if the function doesn't return anything on success. That's about as generic as one can get with a single "interface" type.

[1]: https://docs.spring.io/spring-framework/docs/current/javadoc...

Post reply on HN