4 ms·
All “try” does is allow you to write those three lines as five characters. In natural languages the more frequent used a word is the shorter that word tends to
by qtplatypus 7y ago
All “try” does is allow you to write those three lines as five characters. In natural languages the more frequent used a word is the shorter that word tends to be. “Check for errors and return” is something that is frequently said in go, following from those principles it should be something that it short to write.
- marcus_holmes 7y agoI see that, but it breaks the rhythm, and introduces an alternative syntax that makes it harder, not easier, to read. And code should be easier to read than to write, because we're going to read it way more than we write it. Instead of "do something, check for errors, do something, check for errors" we would have "do something, check for errors, try something, do something, check for errors" (assuming not all errors are going to be "try"d, and some will need to be wrapped). It stops being obvious when I've missed an error-check. That's bad.
- qtplatypus 7y agoHow can you miss an error check? Either you have used try and therefor there has been a check for errors. Or you have not used try and therefor you had to assign to err and therefor you have to use a check for errors. Any assignment to err indicates you need to check for errors just like it is currently.