7 ms·
It looks like instead of making a better error handling system, they just made it easier to not type `if err != nil` everywhere. Then there's all that handler s
by kenhwang 7y ago
It looks like instead of making a better error handling system, they just made it easier to not type `if err != nil` everywhere. Then there's all that handler stuff that looks very much like Java's `try ... catch` in reverse order.
Pretty underwhelming for what's supposed to be a modern language.
- tjholowaychuk 7y agoWhich can be solved with a snippet bound to `e`.
- eikenberry 7y agoThe problem `try` is addressing isn't typing the boilerplate, it is that it clutters up the code making it harder to read.
- dnautics 7y agoit's not as if `if err != nil` doesn't clutter up the code!
- eikenberry 7y agoSorry, I said that poorly. I mean that the problem `try` is fixing is that all the `if err != nil ..` clutters up the code and they are introducing `try` to clean that up.
- zellyn 7y agoIs Go “supposed to be a modern language”? I'm not sure even the language designers would agree with that characterization.
- Thaxll 7y agoWhat is a modern language anyway?
- BlueTemplar 7y agoWell, for one, it handles text as being UTF-8 by default, even at the lowest level (and in no case assumes that byte = character !)
- pjmlp 7y agoOne that takes into account features that have made into the mainstream during the last 20 years, instead of feeling like an Algol-68 subset.
- Thaxll 7y agoI don't care about the features in the last 20 years if I'm able to do my job efficiently which Go as a language provides. Never wonder why those great academics languages with a ton of features are not adopted?
- pjmlp 7y agoSo now languages like Java, Swift, Kotlin are academic languages?
- staticassertion 7y agoIf you don't care about literally decades of progress you're just a bad software developer.
- geodel 7y agoI see Javascript made it mainstream for all sort of clients and servers, Electron desktop apps made it to mainstream. So I remain skeptic to argument just because new features have been invented they are good or need to be implemented everywhere.
- krferriter 7y agoI would say it is a modern language or attempts to be one, as it was designed recently, and was able to take lessons from a variety of older languages. Rust and Go are probably the most popular general purpose, good performance modern languages. Swift and TypeScript are also pretty modern.
- jerf 7y ago"Then there's all that handler stuff that looks very much like Java's `try ... catch` in reverse order." The key characteristic of Go's error handling is that you have to handle errors in the scope in which they occur, vs. exception handing which is designed around throwing errors up the stack until something finally handles it, often quite distant from the point of the error and lacking context. "try" just re-spells that. It isn't a step towards exception handling; it's exactly as "exception-handle-y" as if err != nil { return err } already is, whatever value you may consider that to be. Part of the goal is to make correct handling where you actually do something with the error that much easier, instead of having to do something essentially unrefactorable for every error, through a combination of allowing error handling to be factorable in this new scheme, and some other changes to errors to add more structure by convention to create official ways of composing them together and examining these composed errors in sensible ways.
- pacala 7y agoThe confusing part is the underlying assumption that there exists a way to "handle" errors, understood as a way to workaround the error and somehow continue execution. This is most of the times futile, there is nothing to "handle", other than abort the execution and report the condition. For example, consider a bug that causes a data structure invariant to be violated. The correct "handling" of the situation is to fix the bug and rerun the code, not add layers and layers of error "handling" code ahead of time.
- tptacek 7y agoThat's literally the case that "panic" is there to handle.
- pacala 7y agoThe example was a worst case example. There are weaker versions thereof, for example the familiar: def handle(request): try: return Response(200, process(request)) except UserError as ex: return Response(400, ex.message) except InternalError as ex: return Response(500) The principle stays the same, there is not much to "handle" and no option to recover without external help, either by providing a well-formed request for 400 errors or by providing well-behaving code for 500 errors.
- pjmlp 7y agoIt still needs to catch up with CLU, released on 1973.
- AnimalMuppet 7y agoIn what way?
- pjmlp 7y agoGenerics to start with.
- staticassertion 7y agoGo is new, not modern.