TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Errors vs. exceptions in Go and C++ in 2020

63 pointsby yuribroover 4 years ago

6 comments

marcus_holmesover 4 years ago
I think they missed the point of Go&#x27;s convention. It&#x27;s designed to force people to handle the damn error as near to the call as possible.<p>I&#x27;ve seen way too many programs with a single exception handler right at the base of the program, that just goes &quot;whoops, something bad happened, bye!&quot;. I&#x27;ve even seen this anti-pattern used with Go&#x27;s panic-recover mechanism.<p>It&#x27;s an interesting find though, that the actual performance cost for checking the error return is random, variable, and small. Good to know :)
评论 #25845583 未加载
评论 #25846223 未加载
评论 #25848211 未加载
评论 #25846002 未加载
评论 #25845429 未加载
评论 #25846352 未加载
评论 #25845611 未加载
评论 #25845338 未加载
评论 #25846812 未加载
评论 #25848398 未加载
评论 #25846286 未加载
enriqutoover 4 years ago
As a famous software philosopher said (I think it was Uriel): errors are wrong.<p>Or, to put it more clearly: there are no errors, only conditions that you dislike. It&#x27;s better to not burden your programming with your emotional shortcomings, and treat all conditions that you may encounter on an equal footing.<p>You try to open a file; the file may or may not exist, and both cases are equally likely and you get to decide what your program does in each case. No need to attach an emotionally charged label like &quot;error&quot; in one of the two cases of the conditional. Or worse, as some emotional fanatics do, to bend an otherwise clean programming language by adding features (e.g., exceptions) that help support your sentimental disposition.
评论 #25848286 未加载
tankenmateover 4 years ago
The one item I&#x27;d really contend is where it says it &quot;makes it easier to ... maintain over time&quot;.<p>That might be true for smaller code bases (tracking down exceptions generated from libraries called from libraries, fun!), or code bases where you don&#x27;t use closed external libraries (that can generate unknowable exceptions), or you use only synchronous code (because asynchronous exceptions wind up jumping to fishkill, welcome to distributed systems (logically, physically or chronologically distributed)).<p>[EDIT] fixed thinko
评论 #25846673 未加载
评论 #25846660 未加载
评论 #25846403 未加载
mseepgoodover 4 years ago
Are they going to do this again after Go has switched to a register-based calling convention? <a href="https:&#x2F;&#x2F;go.googlesource.com&#x2F;proposal&#x2F;+&#x2F;refs&#x2F;changes&#x2F;78&#x2F;248178&#x2F;1&#x2F;design&#x2F;40724-register-calling.md" rel="nofollow">https:&#x2F;&#x2F;go.googlesource.com&#x2F;proposal&#x2F;+&#x2F;refs&#x2F;changes&#x2F;78&#x2F;24817...</a>
评论 #25845447 未加载
knz42over 4 years ago
FYI these results were presented at the Go Systems Conf SF last December: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=inrqE0Grgk0&amp;t=15126s" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=inrqE0Grgk0&amp;t=15126s</a>
peterohlerover 4 years ago
Great article! As a performance dweeb, any information on how best to squeeze out a bit more performance is welcome. I might have to play with using panics in OjG (<a href="https:&#x2F;&#x2F;github.com&#x2F;ohler55&#x2F;ojg" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ohler55&#x2F;ojg</a>) and see if it gives a boost.