News for hackers. Stuff that matters.
Re:I have complicated feelings about TDD by ethbr0 on Thursday August 18, 2022 @01:36PM (#32512619)
I forget which famous Unix personality the quote / story comes from, but it amounts to "The perfect program is the one you write after you finish the first version, throw it in the garbage, and then handle in the rewrite all the things you didn't know that you didn't know."

That rings true to my experience, and TDD doesn't add much to that process.

Re:I have complicated feelings about TDD by michaelchisari on Thursday August 18, 2022 @06:43PM (#32515711)
Screenwriters encourage a "vomit draft" -- A draft that is not supposed to be good but just needs to exist to get all the necessary parts on the page. Then a writer can choose to either fix or rewrite, but having a complete presentation of the story is an important first step.

I've advocated the same for early projects or new features. Dump something bad and flawed and inefficient, but which still accomplishes what you want to accomplish. Do it as fast as possible. This is your vomit draft.

I strongly believe that the amount a team could learn from this would be invaluable and would speed up the development process, even if every single line of code had to be scrapped and rebuilt from scratch.

Re:I have complicated feelings about TDD by BearfootCoder on Friday August 19, 2022 @05:28AM (#32519015)
The idea of the vomit draft works for narrative text because it's aimed at human consumers and humans are very adaptable when it comes to accepting input. We can absorb a whole bunch of incoherent, inconsistent content and still find the parts in it which make sense, do useful and interesting things.

An executing program is a lot less forgiving, for obvious and unavoidable reasons.

What TDD brings to the table when you are building a throwaway version is that it helps to identify and deal with the things which are pure implementation errors (failure to handle missing inputs, format problems, regression failures and incompatibilities between different functional requirements). In some cases it can speed up the delivery of a working prototype, or at least reduce the chance that the first action that the first non-developer user of your system does causes the whole application to crash.

Genuine usability failures, performance issues and failure to actually do what the user wanted will not get caught by TDD, but putting automated tests in early means that the use of the prototype as a way of revealing unavoidable bugs is not downgraded by the existence of perfectly avoidable ones. It may also make it easier to iterate on the functionality in the prototype by catching regressions during the changes cycle, although I'll admit that the existence of lots of tests here may well be a double-edged sword. It very much depends on how much the prototype changes during the iterative phase, before the whole thing gets thrown away and rebuilt.

And, when you come to building your non-throw away version, the suite of tests you wrote for your prototype give you a check list of things you want to be testing in the next iteration, even if you can't use the code directly. And it seems likely enough that at least some of your old test code can be repurposed more easily than writing it all from scratch.

Re:I have complicated feelings about TDD by lodovic on Friday August 19, 2022 @01:38AM (#32517815)
This is how I write documents - start with the table of contents and fill in the blanks until the document is done.

Isn't there some law as well that states that successful software projects start with a working prototype, and software designed from the ground up is destined to fail?

Re:I have complicated feelings about TDD by spitfire on Friday August 19, 2022 @12:55AM (#32517668)
I'm using "vomit draft" from now on.
Re:I have complicated feelings about TDD by ppseafield on Friday August 19, 2022 @01:41AM (#32517829)
Reminds me of the chapter "Plan to Throw One Away" from The Mythical Man Month.

> In most projects, the first system built is barely usable. It may be too slow, too big, awkward to use, or all three. There is no alternative but to start again, smarting but smarter, and build a redesigned version in which these problems are solved. The discard and redesign may be done in one lump, or it may be done piece-by-piece. But all large-system experience shows that it will be done. Where a new system concept or new technology is used, one has to build a system to throw away, for even the best planning is not so omniscient as to get it right the first time.

Re:I have complicated feelings about TDD by sdevonoes on Thursday August 18, 2022 @04:19PM (#32514381)
Exactly. I write my programs/systems a few times. Each time I discard the previous version and start from scratch. I end up writing code that's easy to test and easy to swap parts if needed. I also know what TDD brings to the table. On top of that I have over 15 years of professional experience... so I usually know how to write software that complies with what we usually call "good code", so TDD offers me zero help.

For more junior engineers, I think TDD can help, but once you "master" TDD, you can throw it out of the window: "clean code" will come out naturally without having to write tests first.

Re:I have complicated feelings about TDD by dfinninger on Thursday August 18, 2022 @08:15PM (#32516344)
I was taken by TDD for about six months, years ago. I always felt that I was never good at it because edge cases I hadn’t thought of came up or the interface wasn’t actually the best/cleanest/most maintainable way to write that code.

But it got me thinking about testing while writing the class instead of shoehorning a class into a test just before the PR went up. That’s what I think my takeaway was. To this day I think about not just how clean/maintainable the code is, but also how testable the code is while I am writing it. It really helps keep monkeypatching and mocking down.

Re:I have complicated feelings about TDD by jonstewart on Thursday August 18, 2022 @05:23PM (#32515084)
Ah, but it's the _third_ version, because of Second System Effect. So, really, plan to throw two away. https://en.wikipedia.org/wiki/Second-system_effect
Re:I have complicated feelings about TDD by kastagg on Thursday August 18, 2022 @10:47PM (#32517165)
If you know you're throwing two away, you won't even really start in earnest until the third one.
Re:I have complicated feelings about TDD by rileymat2 on Friday August 19, 2022 @01:21AM (#32517760)
This is one of the better points I have ever seen made, bravo. So true.
Re:I have complicated feelings about TDD by pez_dev on Thursday August 18, 2022 @06:54PM (#32515798)
I’ve heard something similar once, but I don’t remember where:

“Write it three times. The first time to understand the problem, the second time to understand the solution and the third time to ship it.”

Re:I have complicated feelings about TDD by pricechild on Thursday August 18, 2022 @05:16PM (#32515010)
Re:I have complicated feelings about TDD by lkrubner on Thursday August 18, 2022 @06:31PM (#32515629)
Whoever said that specific quote, it is a paraphrase of a point that Alan Kay has been making since the late 1970s. His speeches, in which he argued in favor of SmallTalk and dynamic program, make the point over and over again. I believe he said almost exactly the words you are quoting.
Re:I have complicated feelings about TDD by ethbr0 on Thursday August 18, 2022 @07:56PM (#32516224)
That was my paraphrase. From fuzzy memory, don't think it was Alan Kay, but I'm sure the approach is common with that crowd.

The only other clue I have is that it was apparently someone who was super productive and wrote a ton of the early common Unix tools.

Re:I have complicated feelings about TDD by RexM on Thursday August 18, 2022 @04:52PM (#32514743)
I'm almost positive Joe Armstrong has some version of this quote. I couldn't find it, though.
Re:I have complicated feelings about TDD by intelVISA on Thursday August 18, 2022 @10:39PM (#32517132)
I wish more places followed this.

Doesn't matter how good you are the v1 of a program in an unknown area is always complete crap but lets you write an amazing v2 if you paid attention making v1.

Re:I have complicated feelings about TDD by andy_ppp on Friday August 19, 2022 @01:51AM (#32517877)
I think this is what the best programmers do, they are always rewriting things…
Re:I have complicated feelings about TDD by dgb23 on Thursday August 18, 2022 @03:22PM (#32513780)
Well except for the second step where you aim precisely.
Re:I have complicated feelings about TDD by roeles on Friday August 19, 2022 @11:35AM (#32522309)
I've heard Sape Mullender from bell labs (and plan 9) say it during classes he tought.
Re:I have complicated feelings about TDD by FridgeSeal on Thursday August 18, 2022 @06:52PM (#32515779)
Normalise early-stage re-writes.

(Only slightly joking)