News for hackers. Stuff that matters.
Re:An External Replication on the Effects of Test-driven Dev... by mseebach on Wednesday October 19, 2016 @12:56AM (#12741181)
From experience, the value of TDD (or any style of automated tests, really, you don't really have to be driven by them) only really kicks in when the code is of a certain size, complexity and age. They are much closer to a tax in the early phases when you can reasonably keep the full scope readily in your mind.
Re:An External Replication on the Effects of Test-driven Dev... by ivan_gammel on Wednesday October 19, 2016 @04:49AM (#12742175)
>or any style of automated tests, really, you don't really have to be driven by them

Looks like you misunderstood what TDD is. TDD is not a method of testing, it's the method of design of system architecture, in which you formalize the contracts and design APIs by writing examples of their use in tests. Because of that TDD is applicable on every scale (e.g. even when you design complicated algorithm that can fit in just couple of screens) and because of that TDD must be compared not to other test methods, but to other methods of design.

Of course, that comparison will not show the supremacy of TDD for many reasons, like, for example, insufficient expressiveness of testing framework or domain specifics. TDD is useful as one of the many tools we have today, but it shall never be the only tool.

Re:An External Replication on the Effects of Test-driven Dev... by spatulon on Wednesday October 19, 2016 @07:02AM (#12742706)
This benefit of test-driven design is not obvious (at least it wasn't for me) until you really experience it. Several years back I wasn't aware of the concept of dependency injection, but independently discovered it while trying to unit test some error logging functionality. Previously I'd always used a global/singleton logger object. That always felt wrong, but I always assumed it was necessary until writing unit tests forced me to avoid that design.

Also note that TDD is not the only way of getting this benefit. IMHO Paul Graham's essay Programming Bottom Up[1] and Casey Muratori's concept of 'compression-oriented programming'[2] both espouse this same idea of improving API design by "writing examples of their use."

[1] http://www.paulgraham.com/progbot.html

[2] https://mollyrocket.com/casey/stream_0019.html

Re:An External Replication on the Effects of Test-driven Dev... by ivan_gammel on Wednesday October 19, 2016 @08:09AM (#12743032)
Well, I practiced TDD for no less than 10 years, and its benefits are still not obvious, more like something that needs to be continuously reviewed in the context of the current work. Once you've understood all the design patterns that TDD enforces, you don't need TDD to use them. You just think how you _would_ test your code and defer test implementation for future.
Re:An External Replication on the Effects of Test-driven Dev... by platz on Wednesday October 19, 2016 @11:44AM (#12744793)
Why not just learn the patterns directly?
Re:An External Replication on the Effects of Test-driven Dev... by ivan_gammel on Thursday October 20, 2016 @09:05AM (#12751830)
:) Who said they should not be learned directly? TDD is just a good demonstration of their use.
Re:An External Replication on the Effects of Test-driven Dev... by mempko on Wednesday October 19, 2016 @11:59AM (#12744963)
While you are right that TDD is about design, and that it creates examples of use and contracts in a sense. There are better methods for this purpose like Design by Contract which in my opinion is a superior method. Why?

Mostly because TDD process of red-green-refactor is an evolutionary process. Like taking mother nature to design.

It's un-intelligent design....hahahha

Re:An External Replication on the Effects of Test-driven Dev... by pmontra on Wednesday October 19, 2016 @07:51AM (#12742937)
TDD means that you write tests first, see them fail, write the code, see the tests pass. Writing the code first and then the tests is not TDD. I didn't find much value in tests first, especially because sometimes I really dont don't have any idea of what tests to write and I have to sketch some code anyway. I tend to write some code, then its tests and use them to debug my code. I save the time spent to write some tests that will be irrelevant to the code I eventually end up writing. In very few cases, let's say twice per year, I have to solve very clear algorithmic problems with very well defined inputs and outputs. Example: process the elements of an array and return another array. Then I write the tests first.

Anyway, tests first or tests later both are good. No tests is a nightmare as a couple of projects I've just inherited are reminding me today.

Edit: typoes

Re:An External Replication on the Effects of Test-driven Dev... by onion2k on Wednesday October 19, 2016 @01:17AM (#12741279)
I have a somewhat different experience. I've found TDD is useful on even tiny projects because using TDD forces you to write better code. It's really hard to reliably test things that use "magic" and side effects that affect parts of your code they shouldn't really be affecting, and really easy to test things that have well-defined and properly documented interfaces that only do one thing. Consequently writing tests, even if you never actually run them, makes your software better.
Re:An External Replication on the Effects of Test-driven Dev... by js8 on Wednesday October 19, 2016 @02:48AM (#12741625)
I would humbly suggest that because you and parent (and other people here) have such a different positive experience with TDD, that you cannot quite agree when it works, only that it sometimes works, then this is a big indication that TDD is just a placebo.

But maybe that's what's needed - a placebo to feel you better as a programmer, and thus making you more productive through your feelings.

Re:An External Replication on the Effects of Test-driven Dev... by falcolas on Wednesday October 19, 2016 @10:03AM (#12743825)
> TDD is just a placebo

This is my experience. I've watched teams do TDD, only to come up against their first refactor and have to change 80% or more of the tests. Just the other day, they were griping about a code review that they had to do which involved changes to 2,000 lines of test code over a code change with minimal functionality change.

TDD has the effect of making you think differently about how you code. Thinking about how you write code is a good thing, but you don't need TDD to make you think differently about your code. You just need to think.

Re:An External Replication on the Effects of Test-driven Dev... by mseebach on Wednesday October 19, 2016 @05:10AM (#12742279)
I can't speak for the other person, but from my reading, we don't actually have very different experiences. We seem to agree on the value of testing of large/complex project, but have a (minor) difference of opinion over the value of testing in very small projects. Indeed, I'm pretty sure we're deep into hair-splitting territory, as I do agree that TDD'ing small projects can lead to better code, I just don't think the pay off is as obviously big as it is for more complex ones.

It's like observing two fans debate which Star Wars movie is the best and the merits of Jar Jar Binks, and concluding that because they disagree, in fact all Star Wars movies must be pretty bad.

Re:An External Replication on the Effects of Test-driven Dev... by js8 on Wednesday October 19, 2016 @05:43AM (#12742400)
> and concluding that because they disagree, in fact all Star Wars movies must be pretty bad

No, I am not concluding that the TDD is bad, if anything, I am concluding that it doesn't actually matter. Anyway, I am not even clearly doing that, I just wanted to entertain the idea that some practices (such as TDD) can be placebo, so they subjectively feel as a good thing despite the fact that we cannot measure any effect.

Neither was my intent to touch the moral issue about placebos.. I think if it works for you, do it.

In fact, thinking about it some more, there can even be practices in SW development that have nocebo effect, that is, have no measurable impact, but make you feel worse. Daily scrum meeting comes to mind for me.

Re:An External Replication on the Effects of Test-driven Dev... by crdoconnor on Wednesday October 19, 2016 @04:11AM (#12741991)
I have the same positive experience as both of the above commenters. I've found that there are many other variables which can change its effectiveness though:

* The type of code I'm working on

* How well I remember/understand the full requirements.

* How much of the testing framework is built already and how much I have to build.

* The type of test I'm writing.

* How new the project is.

Re:An External Replication on the Effects of Test-driven Dev... by collyw on Wednesday October 19, 2016 @06:48AM (#12742656)
Yes, TDD seems to involve having a decent idea of the requirements (very un-agile). Many projects are making it up as they go along and iterating to a reasonably correct outcome.
Re:An External Replication on the Effects of Test-driven Dev... by crdoconnor on Wednesday October 19, 2016 @08:48AM (#12743249)
It means having a clear idea about the requirement you're implementing at that point in time (not un-agile). It doesn't mean that you have to create a big set of requirements up front (un-agile). You can just pick a story, convert it into a test and implement the code, rinse and repeat.

Writing the test also gives you a second chance to think deeply about the requirement and fix any problems with it before wasting time implementing the wrong thing.

Re:An External Replication on the Effects of Test-driven Dev... by ubu7737 on Wednesday October 19, 2016 @02:57AM (#12741661)
To me it's sort of like people who use an index card when they read. They move it line-by-line down the page so their eyes have an easier time traversing the line of text.

If this is the crutch that makes you a better programmer, who am I to discredit the practice? But dogma has no place in software engineering.

Re:An External Replication on the Effects of Test-driven Dev... by onion2k on Wednesday October 19, 2016 @03:58AM (#12741931)
Kind of like those developers who have to rely on syntax highlighting and linters, right? Those guys! :)

Sometimes using something to help you write better code is just a plain old good idea. You can write it off as unnecessary dogma, but if it actually makes your code better you're shooting yourself in the foot a bit.

Re:An External Replication on the Effects of Test-driven Dev... by rlpb on Wednesday October 19, 2016 @04:12AM (#12741996)
> Consequently writing tests, even if you never actually run them, makes your software better.

It could be argued that an experienced programmer doesn't need TDD to write the same code that TDD could have produced.

Re:An External Replication on the Effects of Test-driven Dev... by gridspy on Wednesday October 19, 2016 @05:25AM (#12742326)
That used to be my attitude too.

However the experienced programmer will be very happy when they don't have to re-test all of the old functionality manually after a large re-factor of some core code.

Re:An External Replication on the Effects of Test-driven Dev... by ivan_gammel on Wednesday October 19, 2016 @05:39AM (#12742376)
Experienced programmer may write tests after the main code is complete to make sure nothing is broken during refactoring. It has nothing to do with TDD.
Re:An External Replication on the Effects of Test-driven Dev... by ivan_gammel on Wednesday October 19, 2016 @04:53AM (#12742189)
That's true. Neither from system design, nor from quality perspective TDD is necessary to produce good code. However, it may still add some value even for experienced programmers, when it's easier to write a test than to build the pure mental model of the domain or the algorithm.
Re:An External Replication on the Effects of Test-driven Dev... by onion2k on Wednesday October 19, 2016 @08:05AM (#12743021)
I've only been a developer for 20 years so I'm not at that point yet.
Re:An External Replication on the Effects of Test-driven Dev... by mikegerwitz on Wednesday October 19, 2016 @08:48AM (#12743253)
Tests provide certain guarantees where compiler proofs (e.g. compile-time errors) are absent. You don't need a large project to realize those guarantees.

Tests aren't just for initial correctness---their benefit is largely in maintenance. They allow you to make changes or refactor the system with guarantees that the covered portions still operate as they were originally designed. There is really no excuse for those types of breaks.

Then there's the team setting: I'm not the only one writing my code. Someone else has to get in there and make changes. I might have to come back months or years later and make changes. At work, we have five developers touching over 100 distinct projects at any point. We have observed that the lack of tests essentially guarantees breaks---we have QA, and there is a direct correlation between bugs and whether code is comprehensively tested.

With regards to TDD: we also observe time and time again that writing code after tests yields untested behavior. There are always odd cases that might not be immediately obvious. There might be a bug that was inadvertently introduced, and now that bug is tested as part of the implementation. Certain branches may not be fully tested. I've seen comments here about this being an experience thing---that more senior developers won't have this problem. That's essentially saying that one is infallible; it doesn't make sense.

TDD also prohibits rushing. Not writing tests is also an excuse to rush the implementation and produce a shitton of unnecessary code. Tests slow you down and force you to think.

Small projects grow. If you don't write tests upfront, when do you write them? We develop incrementally---all of our projects start small, and some of them will remain small for perhaps a year or more until we revisit it. Writing tests at that point loses a lot: we may have forgotten the details of the implementation by then, and the person who originally wrote it might not be involved at all in the changes.

Re:An External Replication on the Effects of Test-driven Dev... by blazespin on Wednesday October 19, 2016 @02:54AM (#12741648)
Absolutely, this. TDD is hugely valuable especially when new people join the project who don't understand and the best way they contribute is by adding tests!
Re:An External Replication on the Effects of Test-driven Dev... by 5gtgd5t5e on Wednesday October 19, 2016 @03:44AM (#12741867)
This is really wrong!

Tests are important, you should not have "the new guy" write them, because they should already have been written, by someone who understood the code being tested. Having some junior dealing with testing is a sure way of producing useless, slow and incorrect tests.

Re:An External Replication on the Effects of Test-driven Dev... by croon on Wednesday October 19, 2016 @04:49AM (#12742172)
That sounds like TLD, the opposite of TDD.
Re:An External Replication on the Effects of Test-driven Dev... by mempko on Wednesday October 19, 2016 @11:55AM (#12744917)
I would say the cost of TDD only kicks in at scale... unit tests are a real cost that plague a project and make devs ultra conservative.
Re:An External Replication on the Effects of Test-driven Dev... by kyberias on Wednesday October 19, 2016 @12:05PM (#12745023)
What do you mean ultra conservative? I can see that the opposite is true: when there are no tests, devs are conservative, ie. they are afraid to change anything. Having at least some tests, they have the possibility to change and refactor more safely.