wnoise comments on Coding Rationally - Test Driven Development - Less Wrong

25 Post author: DSimon 01 October 2010 03:20PM

You are viewing a comment permalink. View the original post to see all comments and the full post content.

Comments (82)

You are viewing a single comment's thread. Show more comments above.

Comment author: wnoise 05 October 2010 03:17:59PM *  1 point [-]

but still I think the least complex one that makes the test pass without copy & paste.

He didn't say "without copy and paste".

Come to think of it, "simplest" varies person to person. In one metric the "simplest that could work" would just be a huge switch statement mapping input for a given test to output for the same test...

(By the way, how did you get that nice fixed-width font?)

http://wiki.lesswrong.com/wiki/Comment_formatting

Enclose with backticks for inline code, and

 start with spaces for blocks.
Comment author: DSimon 06 October 2010 02:09:01PM *  0 points [-]

He didn't say "without copy and paste".

Just copying the expected value from the test into the body of the implementation will make the test go green, but it's completely un-DRY, so you'd have to rip it out and replace it with a non-c&p implementation during the necessary refactor phase anyways.

Wikipedia agrees with me on this, and they cite to "Test-Driven Development by Example" by Kent Beck, the original TDD guy.

So, TDD as I learned it discourages c&p from the test. However, Morendil, now you've got me interested in talking about the possible benefits of a c&p-permitted approach: for example, I can see how it might force the programmer to write more sophisticated tests. Though on the other hand, it might also force them to spend a lot more time on the tests but for only minor additional benefit.