News for hackers. Stuff that matters.
Re:TDD did not live up to expectations by taeric on Thursday June 29, 2017 @12:28PM (#14664549)
You are still writing the tests first, with no real learning from them other than "they are now passing."

It is thought this is like engineering. You design an experiment and then pass it. However, that is not how experiments work. You design an experiment, and then you collect results from it. These may be enough to indicate that you are doing something right/wrong. They are intended, though, to be directional learnings. Not decisions in and of themselves.

So, I probably described something in more of a strawman fashion than I had meant. I don't think that really changes my thoughts here, though.

Re:TDD did not live up to expectations by nostrademons on Thursday June 29, 2017 @12:41PM (#14664659)
You're often learning the optimal API as well. I've had several experiences where I write a library, write some tests for it, and then realize that the library's API is inconvenient in ways X, Y, and Z, and that I could have a much simpler API by moving a few tokens around. When I write the tests first, I tend to get a fairly usable API the first time around, because I'm designing it in response to real client code.

(This all depends on having a clear enough idea of what the library needs to do that I can write realistic test code...I've also had the experience where I write the tests, write the library, and then find that the real system has a "hidden" requirement that isn't captured by the tests and requires a very different way of interacting with the library.)

Re:TDD did not live up to expectations by mayoff on Thursday June 29, 2017 @01:26PM (#14665073)
It’s funny that you say “I'm designing it in response to real client code.“

To me, a test is not real client code. Real client code is code that calls the API in service of the user. E.g. the real client code for the Twitter API is in your preferred Twitter client, not in the tests that run against the Twitter API.

Re:TDD did not live up to expectations by nostrademons on Thursday June 29, 2017 @01:37PM (#14665190)
That's the caveat I mention in my second paragraph.

But yes, if the tests are well-designed and built with actual real-world experience, I do treat them like real client code. Someone looking to use the library should be able to read the unit tests and have a pretty good idea what code they need to write and what pitfalls they'll encounter. And when the library is redesigned or refactored, the tests are first-class citizens; they aren't mindlessly updated to fit the new code, they're considered alongside other client code as something that may or may not have to change but ideally wouldn't.

Re:TDD did not live up to expectations by taeric on Thursday June 29, 2017 @12:44PM (#14664691)
So, this is a slightly different mantra. Working backwards from the customer is an important thing. And if you know that customers will be using your product programmatically, then yes, building the API first is important.

But note, in that world, you aren't necessarily building tests of your software. You are building specifications for your API. I can see how these might be seen as similar. And for large portions of your code, they can be.

However, for the vast majority of your code, it exists to help out other parts of your code. Not to be used as a library/framework by others.

Re:TDD did not live up to expectations by robotresearcher on Thursday June 29, 2017 @03:54PM (#14666356)
> with no real learning from them other than "they are now passing."

You don't learn much the moment the test passes. But designing and writing the test requires understanding the requirements in detail, which is often a learning process.

Re:TDD did not live up to expectations by ericgunnerson on Thursday June 29, 2017 @03:45PM (#14666285)
Author here...

This discussion on what happens - or doesn't happen - after the tests are passing is precisely the point of the article.

The idea of TDD is that every test you look at the existing code and improve it. The majority of developers I've seen trying TDD do this with small code but do not with significant codebases, and you end without the benefits.

Re:TDD did not live up to expectations by sb8244 on Thursday June 29, 2017 @12:38PM (#14664635)
You can throw away the test if you don't find value in it. This can be very useful for fleshing out an idea.
Re:TDD did not live up to expectations by taeric on Thursday June 29, 2017 @12:42PM (#14664675)
But this advice should be extended further. Always be willing to throw away the code and the tests. Take the learning.

Be ware, though, that you are not throwing your customers for a bad ride. As soon as you have customers, it is nigh impossible to throw away the code without neglecting them. And they are your ultimate responsibility. Not the code.

Re:TDD did not live up to expectations by sb8244 on Thursday June 29, 2017 @03:11PM (#14666046)
Exactly right, it can be very hard to make changes (even the right changes) once it's in customer hands. Sometimes it is easy, sometimes it is not. However, it's always easy to throw out code that isn't yet committed.
Re:TDD did not live up to expectations by PretzelFisch on Thursday June 29, 2017 @05:36PM (#14667051)
If you wrote the test after you coded your unit,you would not know why it passed. It could be a false positive. When you move on to the next part of the requirement, you can ensure all your tests still pass.

Sometimes the tests give you the starting point of the problem, "what is the simplest way to get result x" with a way to rapidly get feed back that all the requirements are ment as the structure takes form and you refactor all the code.

Re:TDD did not live up to expectations by bluGill on Friday June 30, 2017 @10:40AM (#14671033)
I sometimes write tests that I know will pass. A common example is when the previous version of an algorithm had a bug in some special case. My new algorithm written from scratch doesn't have that special case at all so there is no test for it. However because the last version had that bug there is a lot of fear so I will write a test that it works even though it is inherent in my new algorithm that it works and at no point in the TDD cycle is that test the correct one to write.