3 ms·
I mentioned that these days I write Go for a living, which involves a lot of: if err := thingThatMightFail(); err != nil { ... } so I was sayi
by LukeShu 6y ago
I mentioned that these days I write Go for a living, which involves a lot of:
if err := thingThatMightFail(); err != nil {
...
}
so I was saying that of course I think lots of `if` statements for error handling are reasonable. (Hmm, thinking back, I learned Go in 2012, and my Bash probably peaked in 2013, I wonder if having learned Go made me more amenable to this in Bash.)
I think a single-line `cmd || die "msg"` like in Perl or Ruby is handy and fine. Or maybe even a two-line
some command that might fail ||
die "Some message that is long enough that it wants to be its own line"
But once it starts getting to have multiple statements that you're grouping with `{ }`, just use an `if` statement. If I were reviewing someone's Ruby that had multiple lines after the "or" in "or die", I'd tell them to just use
unless thingThatMightFail
...
end