TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Using tests as a debugging tool for logic errors

38 点作者 simplesort1 天前

5 条评论

recroad1 天前
This article seems like a very long-winded and complicated way to say that we should write tests. Am I missing something here? Wouldn&#x27;t most developers write tests when creating algorithms, let alone something relating to finance as tax calculations? Yes, you should reproduce a defect by writing a failing tests first.<p>Where I hoped&#x2F;thought this piece would go was to expand on the idea of error-prone[1] and apply it to the runtime.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;error-prone">https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;error-prone</a>
评论 #43916246 未加载
jeremyscanvic1 天前
This reminds me of a talk that Leslie Lamport (author of LaTeX &amp; prominent figure in the field of distributed computing) gave recently [1]. I remember him arguing that the difficult part in writing code is not to determine what code to write to compute something, but to determine what this something is in the first place. &quot;Logic errors&quot; are really about valid algorithms that end up computing the wrong thing - they&#x27;re gonna compile, they&#x27;re gonna run, but they won&#x27;t do what you want them to do.<p>One example he gives is computing the maximum element in a sequence of numbers. This is something trivial to implement but you need to decide what to do with the obvious edge case: empty sequences. One solution is to return some kind of error or exception, but another is to extend what we mean by the largest element in a sequence the way mathematicians typically do. Indeed, the maximum function can be extended for empty sequences by letting max([]) := -infinity, the same way empty sums are often defined as 0, and empty products as 1. The alleged benefit of following the second approach is that it should lead to simpler code&#x2F;algorithms, but it also requires more upfront thinking.<p>[1] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=tsSDvflzJbc" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=tsSDvflzJbc</a>
pkoird1 天前
Closely related are in-code assertions. I remember when I used to liberally use asserts inside a code (and you could disable them for production) to check pre-conditions, post-conditions, or any invariants. Nowadays, I don&#x27;t think the pattern is recommended anymore, at least in certain popular languages.
评论 #43920301 未加载
codr7大约 19 小时前
Something&#x27;s seriously messed up with the font on that page for me.
pfdietz大约 22 小时前
How do you determine if your tests are good at finding logic errors?<p>Mutation testing. Introduce artificial logic errors and see if your tests find them.<p>Disappointed the article didn&#x27;t go into this. You can even use mutation as part of a test generator, saving the (minimized) first test input that kills a mutant. You still need some way of determining what the right answer was (killing the mutant just involves seeing it does something different from the unmutated program.)