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.

Assert() in the hands of bad coders

18 pointsby deafcalculusabout 8 years ago

4 comments

michaeltabout 8 years ago
<p><pre><code> Normally, asserts are only compiled into debug versions of the code, and removed for release versions. </code></pre> I know a lot of languages default to this, and it always seemed like a bad decision to me. The performance benefits of most checks are trivial compared to the major downside of not testing the exact code you release.<p>Several times I&#x27;ve had to track down bugs that have been very difficult to find, as they were &#x27;fixed&#x27; by side effects of assert statements and hence didn&#x27;t show up in debug builds.<p>If a check really can&#x27;t be performed in the release version for performance reasons, just separate it out into a unit test.
评论 #13976380 未加载
评论 #13976322 未加载
评论 #13976424 未加载
wruzaabout 8 years ago
The rule is simple: you never assert() things that can happen, you assert ones that <i>can not</i>.
onion2kabout 8 years ago
<i>This use of assert is silly. The code should look like this:</i><p>In examples 2, 3 and 4 the author explains what&#x27;s wrong with the code and why it&#x27;s a bad use of assert(). In example 1 though it&#x27;s just called silly. What&#x27;s wrong with that one?
评论 #13975869 未加载
评论 #13976184 未加载
评论 #13976235 未加载
xutopiaabout 8 years ago
The nuance of calling people names is lost on the author. Bad code can be written by great coders. It happens to the best of us. No need to insult people to improve code.
评论 #13976456 未加载
评论 #13976484 未加载
评论 #13976250 未加载