4 ms·
The question mark in Rust is equally explicit in the case where it can be used to simply pass the error along.
by gregwebs 8y ago
The question mark in Rust is equally explicit in the case where it can be used to simply pass the error along.
- steveklabnik 8y agoAnd in cases where you don’t, various combinators let you handle common patterns more easily too. You can also write it Go style if you prefer; we started off with exactly that, then moved to a macro, then turned that macro into ?. That all being said, none of that feels very Go-like, so it makes sense that they haven’t followed what we did.
- everdev 8y agoI personally prefer the more concise version :)
- vram22 8y ago>You can also write it Go style if you prefer; we started off with exactly that, then moved to a macro, then turned that macro into ?. Interesting. Does the Rust book (you wrote), explain the difference between the Go style and the current Rust style, and explain how to use the Rust style (well)? Asking because I've found this Some / None stuff (also there in other languages like F#) a little tricky to understand (although I have not spent a lot of time on it yet).
- steveklabnik 8y agoWe talk about it a little, but the best resource on this topic by far is https://blog.burntsushi.net/rust-error-handling/ https://blog.burntsushi.net/rust-error-handling/ which works the whole way from first principles. It was in the first edition of the book but due to space requirements didn’t really fit in the second edition.
- vram22 8y agoThanks, will check that blog out.
- steveklabnik 8y agoNo problem! In general, burntsushi’s work is some of the best in Rust. He’s also very fluent in Go.
- vram22 8y agoGood to know, will check out his stuff in both languages, thanks.
- kjeetgill 8y agoOn a related note, Rust's hygenic macro system is simply amazing. If you're only familiar with macros from C or C++ take a look. The basic idea is that your macro fictions don't use input text and output text. Instead they accept an Abstract Syntax Tree and return a known AS THE. That way the expansion plays well with the grammer. It also manages separate variable scopes well. You only get bleed if you want it. I used to shudder at the thought of macros but I'm convinced. Java or Go could use them reasonably I think. I'm not a rust programer so my understand is probably a little wrong. I'm not intimately familiar with all of the details. Correct me if I'm mistaken!