Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

25
  • 43
    Good answer, but maybe you should mention testing. How does one deal with infinite loop in unit test ? Doesn't such loop 'break' the tests ??? Commented Apr 17, 2016 at 9:39
  • 150
    @GameAlchemist That's the pizza test. If my code doesn't stop running in the time it takes me to make a pizza I start to suspect something is wrong. Sure it's no cure for Alan Turing's halting problem but at least I get a pizza outta the deal. Commented Apr 17, 2016 at 9:52
  • 12
    @CodeYogi - actually, it can get very close. Start with a test that operates on a single value. Implement the code without a loop. Then write a test that operates on two values. Implement the loop. It is very unlikely you'll get a boundary condition wrong on the loop if you do it like this, because in almost all circumstances either one or the other of these two tests will fail if you make such a mistake. Commented Apr 17, 2016 at 18:16
  • 16
    @CodeYogi Dude all due credit to TDD but Testing >> TDD. Outputting a value can be testing, getting a second set of eyes on your code is testing (you can formalize this as a code review but I often just grab someone for a 5 minute conversation). A test is any chance you give an expression of your intent to fail. Hell you can test your code by talking through an idea with your mom . I've found bugs in my code when staring at the tile in the shower. TDD is an effective formalized discipline that you don't find in every shop. I've never once coded anywhere where people didn't test. Commented Apr 17, 2016 at 18:38
  • 13
    I was coding and testing years and years before I'd ever heard of TDD. It's only now that I realize the correlation of those years to the years spent coding while wearing no pants. Commented Apr 18, 2016 at 6:44