当我遇到 this问题时,我正在浏览StackOverflow.在这里,作者提到了他/她的调试风格: I am wondering how to do debugging. At present the steps I follow is, I complete a large script, Comment everything but the portion I
I am wondering how to do debugging. At present the steps I follow is,
- I complete a large script,
- Comment everything but the portion I want to check
- Execute the script
在其中一个答案中,另一个用户说提问者正在以错误的方式调试:
Your sequence seems entirely backwards to me. Here’s how I do it:
- I write a test for the functionality I want.
- I start writing the script, executing bits and verifying test results.
- I review what I’d done to document and publish.
我对编程很新,我遵循第一种做事方式.似乎第二种方式称为测试驱动开发,它似乎是一种非常低效的做事方式.
你能用更简单的方式解释TDD及其优点吗?
I follow the first way of doing things.
许多其他人也是如此
… the second way … seems to be a very inefficient way of doing things.
所有新的和不同的东西似乎效率低下.习惯于其他人都错了,你是对的.
你的职业生涯的其余部分将充满这种感觉.每一件新事物似乎效率低下.并且总是效率低下.
Can you explain TDD and its merits in a simpler way?
是.
TDD更有效率,因为它更有效.
你必须做测试.您可以先写或最后编写测试.无论哪种方式,你必须写它们.
您可以“评论除我要检查的部分之外的所有内容”,并尝试以缓慢,无效的方式查找错误.它通常是无效的,因为 – 如果没有测试来推动您的开发 – 您可能会编写无用的代码或浪费时间.
或者您可以编写测试并编写以有效方式通过测试的最少代码.