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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

It's not enough for a program to work – it has to work for the right reasons

125 点作者 BerislavLopac8 个月前

17 条评论

peterldowns8 个月前
Haven&#x27;t seen it mentioned here in the comments so I&#x27;ll throw in — this is one of the best uses for code coverage tooling. When I&#x27;m trying to make sure something really works, I&#x27;ll start with a failing testcase, get it passing, and then also use coverage to make sure that the testcase is actually exercising the logic I expect. I&#x27;ll also use the coverage measured when running the entire suite to make sure that I&#x27;m hitting all the corner cases or edges that I <i>thought</i> I was hitting.<p>I never measure coverage percentage as a goal, I don&#x27;t even bother turning it on in CI, but I do use it locally as part of my regular debugging and hardening workflow. Strongly recommend doing this if you haven&#x27;t before.<p>I&#x27;m spoiled in that the golang+vscode integration works really well and can highlight executed code in my editor in a fast cycle; if you&#x27;re using different tools, it might be harder to try out and benefit from it.
评论 #41863499 未加载
maxbond8 个月前
&gt; It&#x27;s not enough for a program to work, it has to work for the right reasons. Code working for the wrong reasons is code that&#x27;s going to break when you least expect it.<p>This reminds me of the recent discussion of gettiers[1]. That article focused on Gettier bugs, but this passage discusses what you might call Gettier features.<p>Something that&#x27;s gotten me before is Python&#x27;s willingness to interpret a comma as a tuple. So instead of:<p><pre><code> my_event.set() </code></pre> I wrote:<p><pre><code> my_event,set() </code></pre> Which was syntactically correct, equivalent to:<p><pre><code> _ = (my_event, set()) </code></pre> The auto formatter does insert a space though, which helps. Maybe it could be made to transform it as I did above, that would make it screamingly obvious.<p>[1a] <a href="https:&#x2F;&#x2F;jsomers.net&#x2F;blog&#x2F;gettiers" rel="nofollow">https:&#x2F;&#x2F;jsomers.net&#x2F;blog&#x2F;gettiers</a><p>[1b] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41840390">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41840390</a>
评论 #41861945 未加载
评论 #41864058 未加载
评论 #41862026 未加载
评论 #41861153 未加载
BerislavLopac8 个月前
&gt; How do I know whether my tests are passing because they&#x27;re properly testing correct code or because they&#x27;re failing to test incorrect code?<p>One mechanism to verify that is by running a mutation testing [0] tool. They are available for many languages; mutmut [1] is a great example for Python.<p>[0] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Mutation_testing" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Mutation_testing</a><p>[1] <a href="https:&#x2F;&#x2F;mutmut.readthedocs.io" rel="nofollow">https:&#x2F;&#x2F;mutmut.readthedocs.io</a>
评论 #41861284 未加载
评论 #41861715 未加载
评论 #41860492 未加载
dan-robertson8 个月前
One general way I like to think about this is that most software you use has passed through some filter – it needed to be complete enough for people to use it, people needed to find it somehow (eg through marketing), etc. If you have some fixed amount of resources to spend on making that software, there is a point where investing more of them in reducing bugs harms one’s chances of passing the filter more than it helps. In particularly competitive markets you are likely to find that the most popular software is relatively buggy (because it won by spending more on marketing or features) and you are often more likely to be using that software (for eg interoperability reasons) too.
评论 #41861246 未加载
lo_zamoyski8 个月前
As the Dijkstrian expression goes, testing shows the presence of bugs, not their absence. Unit tests can show that a bug exists, but it cannot show you that there are no bugs, save for the particular cases tested and even then, only in a behaviorist sort of way (meaning, a your buggy code may still produce the expected output for tested cases). For that, you need to be able to <i>prove</i> your code possesses certain properties.<p>Type systems and various forms of static analysis are going to increasingly shape the future of software development, I think. Large software systems especially become practically impossible to work with and impossible to verify and test without types.
foobar84953458 个月前
In my regressions, i make sure i include an &quot;always fail&quot; test, to make sure the test infrastructure is capable of correctly flagging it.
评论 #41861619 未加载
评论 #41861540 未加载
eternityforest8 个月前
I love unit tests, but I sometimes additionally manually step through code in the debugger, looking for anything out of place. If a variable does anything surprising then I know I don&#x27;t understand what I just wrote.
RangerScience8 个月前
Colleagues: If the code works, it’s good!<p>Me: Hmmm.<p>Managers, a week later: We’re starting everyone on a 50% on-call rotation because there’s so many bugs that the business is on fire.<p>Anyway, now I get upset and ask them to define “works”, which… they haven’t been able to do yet.
评论 #41867102 未加载
kazinator7 个月前
&gt; <i>If the code still works even after the change, my model of the code is wrong and it was succeeding for the wrong reasons.</i><p>If someone else wrote the code, your model of why it works being wrong doesn&#x27;t mean anything is wrong other than your understanding.<p>Sometimes even if you wrote something that works and your own model is wrong, you don&#x27;t necessarily have to fix anything: just learn the real reason the code works, go &quot;oh&quot;, and leave it. :) (Revise some documentation and write some tests based on the new understanding.)
JohnMakin8 个月前
There are few things that terrify me more nowadays at this point in my career than spending a lot of time writing something and setting it up, only to turn it on for the first time and it works without any issues.
评论 #41861164 未加载
评论 #41860929 未加载
评论 #41860795 未加载
krackers7 个月前
Is this not common practice? I&#x27;d expect a good engineer who cares about their work to be just as suspicious if something works _when it shouldn&#x27;t_ as when something doesn&#x27;t work when it should. Both indicate a mismatch between your mental model and what it&#x27;s actually doing.
shahzaibmushtaq8 个月前
The author is simply talking about the most common testing types[0] but in a more philosophical way.<p>[0] <a href="https:&#x2F;&#x2F;www.perfecto.io&#x2F;resources&#x2F;types-of-testing" rel="nofollow">https:&#x2F;&#x2F;www.perfecto.io&#x2F;resources&#x2F;types-of-testing</a>
RajT888 个月前
I had a customer complain once about how great Akamai WAF was, because it never had false positives. (My company&#x27;s WAF solution had many)<p>Is that actually desirable? This article articulates my exact gut feeling.
teddyh8 个月前
&gt; <i>This is why test-driven development gurus tell people to write a failing test first.</i><p>To be precise, it’s one of the big reasons, but it’s far from the <i>only</i> reason to write the test first.
评论 #41861039 未加载
评论 #41861332 未加载
computersuck8 个月前
Website not quite loading.. HN hug of death?
评论 #41860585 未加载
sciencesama8 个月前
Nvidea ?
kellymore8 个月前
Site is buggy
评论 #41861584 未加载