4 ms·
> it forces you to handle error states explicitly, Does it? `if err != nil` is a convention. It's not a checked error. It's like saying "C has explicit array
by jacques_chester 11y ago
> it forces you to handle error states explicitly,
Does it?
`if err != nil` is a convention. It's not a checked error. It's like saying "C has explicit array bounds checking", if the convention was to check it by hand.
For all the hate Java gets, when I have a checked exception, I know what it is going to be. I don't need to dig around in sourcecode trying to work out if I should care or not. I don't need to check which of the three Golang error-distinction idioms (package-variable errors, error subtypes, plain-old-errors-with-magical-strings) is in play.
As you can guess, I don't like Go.
- sagichmal 11y ago> `if err != nil` is a convention. It's not a checked error. It's... obviously both.
- jacques_chester 11y agoSorry, typo. "Checked exception", meaning that the compiler enforces error handling and that you can look a method signature and learn what kind of exceptions the method can throw without needing to read its internals.
- fooster 11y agoAnd runtime exceptions? What about them?
- jacques_chester 11y agoThey leave you in about the same position as a programmer in a dynamic language. The advantage of runtime exceptions over Go is that I will get a fatal crash and a stacktrace. I don't have computation proceeding in an undefined, difficult-to-debug way because I forgot to do `err != nil` somewhere (particularly for functions that only return err).
- fooster 11y agoOr someone will catch it and discard the result which is often often what occurs. For example, with java throw an exception in an executor task (an assertion failure for example). What do you think occurs?
- jacques_chester 11y agoWhich happens in Go too. I've seen a lot of code that happily sails past functions which only return err, meaning the compiler never pipes up. Don't get me wrong, though. I become grumpy when I see empty catch clauses. Or a logger figleaf.
- superuser2 11y ago'err' is sitting there in the return value and the compiler will force you to either use it or explicitly steamroll it. The difference between C bounds checking and Go error checking is that you can't forget to check an error in Go.
- azth 11y agoI guess everyone is remembering to check the return values of fmt.Println() then huh?