Yeah, hard disagree on that. While it’s true that programmers shouldn’t overuse try, it’s still a really good language feature.
Fundamentally, there are 3 things you can do when an error occurs:
- Handle it (takes effort).
- Pass it up the stack.
- Silently ignore it.
In C, passing errors up the stack takes effort (you need to change the function signature, not just add ! in front of it), and ignoring errors is the default option. Guess what the lazy/tired/hurried programmer does?
Then, once you realise you were ignoring an important error, you have to change the function signature at each level from where the error happens to where you can actually handle the error. It’s a massive PITA.
Bubbling-up the errors is much better, because you can come back later and insert error-handling code at whichever level you want. None of the other functions need to be changed.
It was difficult, but I thought of one thing that could be worth removing:
Don’t allow (or severely restrict) implicit type coercion from usize/isize to other integers, regardless of bit width - require @intCast() to be used.
The reason for this came up when I was writing code intended to run on a Raspberry Pi. I was writing and testing it on a 64-bit machine, and had everything working nicely. But when I tried to compile for a 32-bit architecture I got a whole host of compile errors from implicit coercion that suddenly didn’t work.
In my case it was simple to fix, but it’s easy to imagine this happening in a complex library that the author only tested on a single computer, and having to vendor end edit the dependency solely to make it compile for a slightly different architecture.
To emphasize, if I had been forced to add the @intCast() earlier on, I could have cross-compiled without a single change to the code. All I had to do was add a CLI flag. That’s awesome.