4 ms·
Go's error handling is good, but rust's error handling is phenomenal. It just doesn't really show in an 18 line program... Rust and Go both force you to acknowl
by huimang 3y ago
Go's error handling is good, but rust's error handling is phenomenal. It just doesn't really show in an 18 line program... Rust and Go both force you to acknowledge the possibility of errors in your code, whereas python and ruby, etc, will happily let you ignore them until something blows up.
Being able to use `?` in a method that returns `Result<T, Err>` is so elegant and helps readability compared to multiple if err != nil statements in go. In a larger program, ? lets you pass along errors up along the chain until you get to a place where they actually need to be handled, and this lets you consistently deal with them as well. For example, in a slightly more complex example [0], I handle errors on line 162 from monitor_device() (line 176, 181), instead of cluttering up monitor_device() unless I need to. (This was just some prototyping code so please bear with me).
[0] https://github.com/andrewzah/fst_rs/blob/master/src/main.rs#L162 https://github.com/andrewzah/fst_rs/blob/master/src/main.rs#...