4 ms·
Ask HN: Can you do TDD in a complex product (data science, AI, etc)?
I have been considering introducing TDD in my startup . We do a fair bit of non-trivial work in our Python/Flask APIs : credit scoring, accounting, workflows, etc
I'm wondering if TDD is even a good idea ? Can one get to a stage where writing testcases is as easy as writing specs or whiteboarding ?
Or does TDD become one of "those processes that founders shoved down our throat" ?
There was a very interesting discussion about this a few years back on HN - https://news.ycombinator.com/item?id=2240595
P.S. A lot of responses I get are "whatever works for your team". Fair enough. But I'm looking for fairly opinionated answers - how do you do it ? And what would you do better ?
what's your mental model around writing tests ? Do you write tests after every function, every commit , every day ? When you are building a new product (and maybe hacking stuff together in the middle of the night), would you still write tests before moving forward ?
- rajnp 10y agoNot specifically to data science or AI projects, generally test coverage is very important, otherwise how would you ensure that the functionality works as expected and handle error/unexpected conditions? But TDD approach or writing test cases after the implementation is upto the individual developer/team's preference. Initially TDD approach would be very difficult for freshers or devs who don't have TDD experience, but in the long run, it would help.
- jimsmart 10y agoI generally write tests for the initial/main functionality up-front - usually just a simple call to some func that's currently just stubbed, assert that it does the right thing (e.g. "I want to call my new code like this... and get back this..."). Then implement enough code to make that pass, and perhaps modify/expand the test during that process (exercising edge cases perhaps, or adding more functionality - depends on the project). Then I might write a whole bunch of related code, fleshing out other parts which rely on the primary part (that I know works well enough for now), perhaps without writing tests first. But if I do that, I will then go back and write more tests until I get 100% coverage later. Undoubtedly you will find corner cases that you didn't cater for when you exercise the code in tests. It's not done until all my code has 100% coverage, and all the main entry points, important data structs, tricky bits, etc, have documentation of some kind. But I might implement a fair chunk of the code before implementing full tests. So: some tests up-front (because it makes coding easier), and the remainder of the tests (for full coverage) have higher priority than writing documentation on my list of todos. In no particular order, I've written non-trivial amounts of Go, Javascript, C#, Python, Java, C/C++, ... — But your question is not specific enough because the process can vary a lot, depending on what you're coding (e.g. I don't bother writing tests for bash scripts: they usually either work, or they don't), and who / what it is for. e.g. the above process works great if you're building a library (and if you're not building a library, it can help to try and break apart the project into some library-like pieces). Obviously the above would be somewhat different if I were doing TDD for a web-app, but I'd still apply the same process to the bits and pieces that make up the app behind the scenes - and then have to also consider front-end testing if appropriate.
- itamarst 10y agoI like TDD, it's pretty useful in many cases, but... you may be starting this the wrong way around. Your question is "should I use this testing technique?". A better question to start with is "what am I trying to achieve with testing?" Once you know your goal you can find a relevant testing technique to achieve it. Your goals will likely be different for different parts of your product and codebase. Notice this means different organizations and products (or same product at different times in its lifecycle) will have different forms of testing, because they have different goals and resources. To help with the decision process of choosing testing goals I've come up with a model, of different goals and the kinds of testing that are useful for each. I'm going to be giving this as a talk at PyCon in May, but have an essay version written up: https://codewithoutrules.com/2017/03/26/why-how-test-software/ https://codewithoutrules.com/2017/03/26/why-how-test-softwar... Since choice of testing strategy is situation-specific it's very hard to give a general answer without understanding the specifics - ping me (itamar at codewithoutrules dot com) if you'd like to talk over your specific situation.
- brudgers 10y agoIn the context of 'my startup' the decision to implement or not implement TDD or microservices or ReactJS is properly made on the basis of business value. Does TDD/microservices/ReactJS make money or improve the odds of survival or provide a competitive advantage or will it create drag on the business? Good luck.
- itamarst 10y agoThis is good advice... but it's hard to follow if you don't understand the costs of particular forms of testing, or what benefits they provide. This was part of the motivation for creating the model I referenced in a comment above.
- brudgers 10y agoYour earlier question does not make a business case and Markham's answer might be somewhat similar to mine here (unsurprisingly perhaps since I sort of recycle things I read on Hacker News when it comes to startup specific advice and my own experience when it comes ordinary business advice). This sort of falls in the category of both: there is a startup component (survival) and a general business component (YAGNI based cash flow). The tricky thing about TDD is that Uncle Bob packages it up with morals and ethics and craftsmanship. It's probably a big reason why he is a successful consultant in addition to having coding chops...and I don't disagree with his moral and ethical opinions but they are about writing code rather than running a business and here the important decision is running a business and that's what Markham emphasizes and emphasizes particularly well in his reply to Cooper's response. I'd put it this way, the first order benefit of TDD is confidence that refactoring will pass fewer regressions to production. But a successful startup does not depend on refactorings because growth drives rearchitecting and pivoting and those mean that many/much/all existing tests may become irrelevant. Riffing a bit, it might be that in a startup the way to determine the benefit of tests is do they get the company to the point where those tests become irrelevant more quickly? Most startups default on technical debt by either running out of money or by throwing out the code base because they acquire different operating parameters due to scale.
- 10y ago
- nanospeck 10y agoHere is a good link from Robert C Martin (author of clean code) for the question : How doeas the presence of neural nets impact the deve lifecycle in Agile environment http://blog.cleancoder.com/uncle-bob/2017/03/16/DrCalvin.html http://blog.cleancoder.com/uncle-bob/2017/03/16/DrCalvin.htm...