4 ms·
That isn't apples to apples. In Rust I could have done (assuming `anyhow::Error` or `Box<dyn Error + Send + Sync>` return types, which are very typical):
by nu11ptr 10mo ago
That isn't apples to apples.
In Rust I could have done (assuming `anyhow::Error` or `Box<dyn Error + Send + Sync>` return types, which are very typical):
let mut file = File::create("foo.txt")
.map_err(|e| format!("failed to create file: {e}")?;
Rust having the subtle benefit here of guaranteeing at compile type that the parameter to the string is not omitted.
In Go I could have done (and is just as typical to do):
f, err := os.Create("filename.txt")
if err != nil {
return err
}
So Go no more forces you to do that than Rust does, and both can do the same thing.
- Mawr 10mo agoYou could have done that in Rust but you wouldn't, because the allure of just typing a single character of ? is too strong. The UX is terrible — the path of least resistance is that of laziness. You should be forced to provide an error message, i.e. ?("failed to create file: {e}") should be the only valid form. In Go, for one reason or another, it's standard to provide error context; it's not typical at all to just return a bare `err` — it's frowned upon and unidiomatic.
- nu11ptr 10mo ago> You could have done that in Rust but you wouldn't, because the allure of just typing a single character of ? is too strong. You could have done that in Go but you wouldn't, because the allure of just typing two words return err is too strong. Quite literally the same thing and the only difference is bias and habit.