News for hackers. Stuff that matters.
Re:The Generational Divide in Software Developers by js8 on Sunday July 25, 2021 @05:25AM (#27947887)
> I wouldn't go as far as the author saying TTD is useless as it's genuinely useful against most obvious bugs

I am skeptical of TDD, so I have a genuine question. Let's say TDD is able to find the "most obvious" bugs, like a typo. My question is, why are these bugs worth creating a test for them, compared to either manual testing (running the program and looking at the output) or running a portion of the integrated test suite on the code to find them? If the bug is simple and crippling, then the program is likely to fail anyway.

To me there is a tradeoff. With TDD, you write some unit test code, and it finds a trivial bug. But is every trivial bug found worth maintaining the unit test code going forward? I mean it's not like this bug is gonna appear again all of sudden in your code, unless you change it, but then in all likelihood you need to change your unit test as well.

I guess I don't really see TDD as a good tool, because all the situations that you can run into are already covered by other, more specialized tools. If you want to catch edge cases, asserts are IMHO superior tool to tests. If you want to verify your program quickly, running it manually and looking at the output is superior. If you want to verify your program properly, running a comprehensive (and integrated) test suite is superior (the best if you can make it property-based).

There are situations where unit tests are genuinely useful, like writing a library. But in those cases, unit tests seem to always either compare with some other implementation (for example, if I am testing a sin(x) function, my other implementation is the calculator), or at least compare with well-defined specification that comes outside the code. But I feel like majority of tests written for TDD are not really testing the code against anything (simply because another implementation or specification is not available), they just test the intent of the code itself as is written, which might be useful if you wanted to write "bar" but wrote "baz" by accident, but other than this type of bugs, what is their long-term contribution, that could justify the maintenance cost?

Re:The Generational Divide in Software Developers by loopz on Sunday July 25, 2021 @06:20AM (#27948113)
The output of TDD is not the tests themselves, but the process of designing beforehand what is expected behaviour using up-front tests. The tests then acts as a guide to later development of code. Both should be adjusted during the discovery journey. The tests should then reflect the value that the code provides, and must be usable as-is in later refactors to have much worth themselves. "Acceptance criterias" should be self-evident from the ongoing development processes, and is not a final signoff.

TDD tests would ideally be used for hunting business value, and focus on overall desired product behaviour and qualities.

Re:The Generational Divide in Software Developers by EVa5I7bHFq9mnYK on Monday August 02, 2021 @11:45AM (#28038172)
Ultimate TDD is machine learning. You give the machine all the test cases, and it figures out the code. Except it doesn't work as well on out of test samples. Human oversight is still required.
Re:The Generational Divide in Software Developers by js8 on Sunday July 25, 2021 @06:57AM (#27948253)
Are you saying you want to replace the specification with tests? That's really dubious to me.

I don't think it really helps software development, if instead of "here's the description of what we need to do" the SW developer gets "here's a few examples of what we need to do" (albeit if the examples can be automatically verified).

If that's NOT your intent, what's the role of specification in the TDD, and how it's interacting with the implementation and the tests?

Re:The Generational Divide in Software Developers by vikingerik on Monday July 26, 2021 @01:01PM (#27961911)
> Are you saying you want to replace the specification with tests? That's really dubious to me.

That's pretty much it. The value is that tests can be automatically executed and verified. A specification document can't.

Writing a spec is still a step in the process - a bootstrapping step. The spec is a "write one to throw away" placeholder until you get far enough that the spec can be replaced with executable tests.

Re:The Generational Divide in Software Developers by js8 on Monday July 26, 2021 @04:39PM (#27965145)
I don't think tests can ever replace specification, it's like trying to replace a mathematical proof with a computer experiment. Unless it's something like property-based tests, but even there..

My take on specification is that you encode it to be executable as your program, during development. Ideally, the program should encode the specs in the most straightforward way possible. To "specialize" the spec into tests first and then "generalize" it again from tests into a working program seems like unnecessary hassle, and frankly prone to information loss.

It's interesting, because as I state in another comment, I have a big disagreement with a guy who loves TDD. I guess I am a theorist (I derive my feeling of correctness from simplicity of the code) and he is an empiricist (he derives his feeling of correctness from many small tests), and it somehow defines our approach.

Re:The Generational Divide in Software Developers by loopz on Sunday July 25, 2021 @08:33AM (#27948714)
It's just the idea behind Test Driven Development, that tests drive development. It won't be very effective as a handover, though could be used as acceptance criterias if that is needed.

The adherents really want tests to be the specification, as a way to be measurable / testable. Specs may be converted to tests.

But most of it is theory. It all depends, as usual, on the dev(s) and circumstances.

Re:The Generational Divide in Software Developers by fatnoah on Monday July 26, 2021 @12:58PM (#27961863)
My one and only truly TDD project went brilliantly, but there were specific circumstances. In this project, I created the back-end and API while an outsourced team built the UI. What made it work well was that I wrote the tests AND the spec at the same time, and kept both up to date. Completed tests equalled progress on the back-end, made it easy to identify any regressions in my own code, and clear differentiated between logic and general HTTP plumbing errors.
Re:The Generational Divide in Software Developers by groby_b on Monday July 26, 2021 @01:22PM (#27962201)
TDD is double-entry bookkeeping. Done well, you've spec'd the behavior twice, once as constraints, and once as logic. It's of limited utility in the moment, but it's invaluable going forward, as you make changes. (The in-the-moment use is about surfacing API design forces, and I'm not sure TDD is the best way to achieve good design)
Re:The Generational Divide in Software Developers by js8 on Monday July 26, 2021 @04:23PM (#27964950)
I like the double-entry bookkeeping analogy, but isn't it true for all tests? In fact, as the article explains, in the old days it was a specialized QA department (different from development) which wrote tests often just based on specs, and the barrier (also called black-box testing) was there precisely to have independent verification. It seems to me that this argument favors the old methods and not TDD in particular.
Re:The Generational Divide in Software Developers by groby_b on Monday July 26, 2021 @05:09PM (#27965510)
The key is the automation of the tests. I personally hold the belief that the logic author should also be the spec author, and it's QA's jobs to find gaps in your model of the world.

The barrier means QA doesn't have the same model, and often lacks info that you have. That's valuable in some aspects, but it's not double-entry. (Double entry in accounting means that you always record two transactions that need to match each other, not that there's independent verification - that'd be auditing)

I believe you need both double-entry and independent verification. (Of course, that depends on scope & desired quality. Your 100-line bash script that you only run to print fortunes for your friends probably needs less rigor than products that are used by billions, or that have life-or-death impact)

You're right that it's not specifically TDD that enables this - but you do want automated unit tests written by the developer, whatever methodology you use. (Or at least I want them :)

Re:The Generational Divide in Software Developers by EVa5I7bHFq9mnYK on Monday August 02, 2021 @11:30AM (#28037930)
Testing serves the same function as type system in C++ - it imposes restrictions on the code and automates checking for those restrictions. It became absolutely necessary with the advent of type-less languages such as JavaScript or PHP.
Re:The Generational Divide in Software Developers by glopes on Tuesday July 27, 2021 @12:23AM (#27968571)
In my opinion TDD really only exploded in modern SW industry due to the shift to dynamic languages like Javascript and Python where you can’t even rely on the compiler to help you with types and typos.

Unit tests still help of course with static typed languages but you really don’t need to be afraid that refactoring can kill your entire code base as you have formal proof that types and names agree as part of your IDE and build process by default.