Live data from Hacker News

Ask HN: Seriously, how do you TDD?

news.ycombinator.com

41–50 of 86 posts

Re: Ask HN: Seriously, how do you TDD?

#41

There are tons of books about the subject. Can tell us which you already read?

Only Kent Beck’s one, but honestly I might need to revisit it (I only vaguely remember how he approached the two examples on the book). If you have other suggestions of books you found insightful please let me know. Thanks!

Re: Ask HN: Seriously, how do you TDD?

#42
Read about AMDD. The idea is: you not only write tests to design and iterate on that, but also sketch a model of your system and iterate that. Depending on the size you may want to sketch subsystems, etc.

Now the only problem I have with TDD is time. It takes a lot of time to do it right and usually I don't have that time (in my organisation). So maybe you can tdd some parts of your application, maybe the most critical parts. Even for personal projects you may not have the time: demotivation usually kicks in for personal projects. TDD defers results and the positive feedback needed to keep going. At least in my experience

Re: Ask HN: Seriously, how do you TDD?

#44
For me, I usually have an idea for an overall simple design or approach that will likely work. If I'm unsure, I might post an issue that describes the theory of operation for feedback or iteration. TDD is the rest of what follows.

Now what does work is if you can decompose the whole idea into parts, each of which is written using TDD. You might still want to outline some key interfaces so you get the shapes of things to fit. With practice, all this extra stuff often happens in your head as you're doing TDD and you make adjustments along the way.

Also, the way you described making bottom-up things that didn't quite work, is a valid and possibly effective way of doing TDD. If you're able to determine that a lower implementation is unsuitable it can be rewritten and if the tests are not too brittle will give you confidence to do the rewrite safely and faster.

Re: Ask HN: Seriously, how do you TDD?

#45
If you take TDD literally you’ll end up writing the inner domain logic layers first purely because they’re easier to test using objects and APIs. For greenfield projects that’s a risk because you don’t know how that fits with the user/usage side of things.

I’ve found it safer to start with (manual) integration tests where I verify intended behavior from outside in. That avoids building inner layers which turn out to be slightly but annoyingly off compared to what is desired.

Unfortunately, as soon as you jump off the pure OO bits and domain logic, the TDD-ness of your end-to-end program could be all over the place. You’re entirely at the mercy of available tools and your proficiency with them, and the time you can invest in learning those tools.

Re: Ask HN: Seriously, how do you TDD?

#46
post #41

There are tons of books about the subject. Can tell us which you already read?

Only Kent Beck’s one, but honestly I might need to revisit it (I only vaguely remember how he approached the two examples on the book). If you have other suggestions of books you found insightful please let me know. Thanks!

You can also check out Growing OO Software Guided by Tests.

Re: Ask HN: Seriously, how do you TDD?

#47

Don't think in terms of tests -- think in terms of examples. Write examples of how you would like to be able to solve common cases and handle edge cases if you had the ideal interface based on what you know at the time, then use unit tests with stubbed out interfaces as a tool while trying to develop the implementation. Refine and even rewrite your examples as you learn about what works and what doesn't work. Recursi…

This is very interesting. I need to try your ideas. Thanks!

Re: Ask HN: Seriously, how do you TDD?

#48
post #32

Earlier quoted context omitted.

Seconded. Only ever add tests after you have a working version. Starting a greenfield project with TDD is a waste of time. Just get something out then start testing your assumptions with unit tests, even then, don't test the whole codebase, test your fundamental assumptions and core features (like user auth, roles, permissions and their invocations, esp if multi-tenanted).

The way to do it using TDD is to do your greenfield development to the point of a working solution to elicit your fine-grained requirements, then throw that away and rewrite it using TDD. The first version is considered a "spike solution" and is not supposed to touch production. In TDD, all production code must be written against some pre-existing test. Any code which does not meet this criterion is broken.

I have never worked with that sort of time luxury.

Re: Ask HN: Seriously, how do you TDD?

#49
post #42

Read about AMDD. The idea is: you not only write tests to design and iterate on that, but also sketch a model of your system and iterate that. Depending on the size you may want to sketch subsystems, etc. Now the only problem I have with TDD is time. It takes a lot of time to do it right and usually I don't have that time (in my organisation). So maybe you can tdd some parts of your application, maybe the most critic…

Thanks. I found an article about it and it looks like a interesting read.

Re: Ask HN: Seriously, how do you TDD?

#50

I'm not quite getting your categorization of the first approach as top-down and second as bottom-up, they are the opposite to me. Your program is going to have a flow like this: $ rcd2-awesome-finance-app september2022.csv Category Amount Food $100.00 Clothes $200.00 ... Internally it'll be like this: main(string filename) csv = open(filename) cat->$ = new dict() foreach line in csv transaction = parse(line) cat = ca…

Interesting point of view, thanks.
Post reply on HN