5 ms·
TDD is nuts for code without a client or specification. The whole point of tests is to ensure that the code does what it's supposed to do. When you have neith
by nostrademons 11y ago
TDD is nuts for code without a client or specification. The whole point of tests is to ensure that the code does what it's supposed to do. When you have neither client nor spec, how are you supposed to know what the code is supposed to do? There is, IME, a >90% chance that any such code will be ripped out and replaced as you develop a better understanding of the problem domain.
I've found it's pretty useful to go back and add tests as you accumulate users, though (or convince an exec that your project is Too Big To Fail in the corporate world). You're capturing your accumulated knowledge of the problem domain in executable form, so that when you try an alternate solution, you won't suddenly find out - the hard way - that it doesn't consider some case you fixed a couple years ago.
- mhaymo 11y agoI've found the opposite, that TDD helps me most when the spec or my understanding of the spec is fuzzy, by forcing me to make decisions about behaviour up-front and clarify my thinking. Otherwise I can get bogged down trying to implement and specify a feature simultaneously, or spend a lot of time implementing a feature before realising I'm approaching it the wrong way.
- nostrademons 11y agoDepending on how you work, that can be worthwhile, but I usually find I get more useful information quickly by making the decisions that make implementation easiest, getting something up on the screen that I can react to as a user (or put in front of a real user), and then seeing where that initial proof of concept falls short. In general, I've found that pushing off decisions until I have as much information as I can tends to result in better decisions.
- collyw 11y agoYes, its easier to prototype a feature first and get feedback from the users than it is to guess a load of tests to do the same thing.
- te_chris 11y agoI don't agree with this at all as the tests at least say what the code does in its current state. I see that as incredibly useful. It also forces you to think about what it's actually doing as you build it. I get the OP's forest-for-the-trees thing, but I still find incredible value in testing things - even my side projects.
- mbrock 11y agoIf you don't know what the code is supposed to do, how are you writing it?
- Ygg2 11y agoImagine you make some code that needs to comply to a law, but then the law changes. Or client decides he wants his notification in different format, look shape.
- icebraining 11y agoThen you change the test. They are not supposed to be immutable.
- nostrademons 11y agoAnd you've spent 2x the effort that you would've had you not written the test in the first place. My initial comment was meant to be a statement about the relative chance that you're solving the wrong problem vs. solving the problem wrong. Prototypes help you identify that you're solving the wrong problem, unit tests help you identify if you're solving the problem wrong. In the beginning of a project, you are much, much more likely to be solving the wrong problem than solving the problem wrong. Go ensure that the system works end-to-end and solves the user's needs before you make it bulletproof.
- crdoconnor 11y agoSome (quite a lot, actually) pieces of code are essentially experimental - e.g. trying out an API/libary and seeing what it's capable of or trying an approach to solving a particular kind of problem or even trying to see if a particular problem is solvable with a piece of code. For this kind of coding, TDD makes no sense whatsoever. The 'specs' are as fluid as the code and having confidence in the code isn't that important. This is entirely different to creating production hardened systems with very clear specs. If you don't do TDD on that, you're an idiot.
- 11y ago
- crusso 11y agohow are you supposed to know what the code is supposed to do? That's the beauty of TDD. It forces you to sit and work out, "What is this code supposed to do from the client perspective?" It battles the all-too-prevalent developer inclination to just start running with implementation without even taking the time to understand what problem is being solved.
- falsedan 11y ago> TDD is nuts for code without a client or specification. So, write/pretend to be one? I find writing high-level overview docs, and API interface example code before writing code gives enough guidance for my personal project to then write some tests & then code (in any order).