5 ms·
I just got out of a work presentation on new features in C++11 and C++14. The two presenters went into what's apparently the standard debate about noexcept. Thi
by stcredzero 11y ago
I just got out of a work presentation on new features in C++11 and C++14. The two presenters went into what's apparently the standard debate about noexcept. This makes me appreciate Go's pragmatic decision not to have exceptions! When you start getting into the nitty-gritty and epiphenomena around implementing APIs, multiple return values with error codes looks pretty darn good.
Error codes are explicit and devoid of implicit automagic. You're not going to break a lot of contracts and alter semantics by adding a keyword. The error codes are explicitly part of your function signature, in the most stupidly straightforward way possible. If you're going to be a bad developer and ignore error codes, this is going to appear explicitly in your code. (As opposed to being rewarded with "cleaner" code when you sweep exceptions under the rug.)
- catnaroek 11y ago> Go's pragmatic decision not to have exceptions Um, what problems do exceptions introduce that panics don't?
- stcredzero 11y agoNone, but here's the thing about pragmatic design: You just have to make something that's less problematic the common case.
- catnaroek 11y agoExceptions are meant to be used for exceptional situations too. (Heck, the intended use is in the name!) Using them for normal control flow is bad programming style. (I'm looking at you, Python!) In any case, the argument in favor of using return values for handling error conditions would be stronger if Go had proper tagged unions. With tagged unions, you can guarantee that exactly one of an OK result of an error object will be returned. Right now, Go has the very confusing situation that a function might return two `nil`s (the operation neither succeeded nor failed) or two non-`nil`s (the operation both succeeded and failed), neither of which makes any sense.
- dllthomas 11y ago"multiple return values with error codes looks pretty darn good" I'm a fan of making errors explicit, but I continue to find the use of effectively a product type (value and error) to return what is actually a sum type (value or error) to be ugly and error prone. Ideally, invalid states should be unrepresentable. In this case, both "value and error" and "no value and no error" are not. This is not good design.
- stcredzero 11y agoIdeally, invalid states should be unrepresentable. And clearly any language in which invalid states are representable is useless? Nice try, but nah. I like me some pure functions sometimes, but I'm not dogmatic about it.
- dllthomas 11y agoYour response is so bad I almost think you're trolling... Hoping (I think) not: "And clearly any language in which invalid states are representable is useless?" I did not call anything useless, much less the entire language. And I am the first to agree that trade-offs need to be made between a variety of considerations. But in this case, for the approach under discussion, I pointed out a design criteria that I find often important, that this approach is in flagrant violation of, while getting basically (perhaps literally) nothing in return toward any other design considerations. Either I missed things or that's just a bad decision. If you think it's the former, please engage me more constructively so that at least one of us can learn something. "Nice try, but nah." This is needlessly rude. "I like me some pure functions sometimes" This issue has zero to do with pure functions. "but I'm not dogmatic about it." Right, pointing out bad design can only come from a place of dogma. Never experience, never consideration, and never anything that could permit substantive discussion.