7 ms·
A sentiment among members of a former team was that automated tests meant you didn't need to write understandable code - let the tests do the thinking for you.
by Izkata 8y ago
A sentiment among members of a former team was that automated tests meant you didn't need to write understandable code - let the tests do the thinking for you.
This, and stuff like your story, are why I don't trust people who promote test-driven development as the best way to write clean APIs.
- pmarreck 8y agoTDD doesn't think for you, it merely validates your own existing understanding/mental model and forces you to come up with it upfront. This is hardly a thing to be mistrustful about, unless you work with idiots.
- bryanrasmussen 8y agook but from reading a lot of the comments on HN it sounds like many posters here think that they do work with idiots.
- pmarreck 8y agoTouché!
- YeGoblynQueenne 8y agoThose idiots probably also think the same, though.
- setr 8y agoIf everyone’s an idiot tbinking they’re surrounded by idiots, then TDD has no hope to ever succeed !
- danmaz74 8y ago> TDD doesn't think for you I totally agree, but I met several programmers who think the opposite.
- mannykannot 8y agoYou are right about that, but having code that passes a given test suite doesn't say anything about its secondary qualities, such as whether it can be understood. In theory, a failing test could improve your understanding of the situation, allowing you to refactor your initial pass at a solution, but I would bet that on this particular code base, the comprehension-raising doesn't go far enough, in most cases, for this to be feasible.
- Huggernaut 8y agoThat seems orthogonal to testing though. Implementation code can be hard to understand with or without a test suite, at least with test, as you point out, you may be able to understand the behaviour at some higher abstraction.
- sooheon 8y agoRich Hickey called it guard rail driven programming. You'll never drive where you want to go if you just get on the highway and bump off the guard rails.
- carlmr 8y agoExcept that's a really bad analogy. It's more like you set up guard rails, and every time your vehicle hits a guard rail you change the algorithm it uses for navigation until it can do a whole run without hitting a guard rail. I've experienced myself how the code quality of proper TDD code can be amazing. However it needs someone to still actually care about what they're doing. So it doesn't help with idiots.
- sooheon 8y agoI don't think it's a generous analogy, but it's poking fun at being test DRIVEN, rather than driver driven. I think he'd agree with you that it's the thinking and navigating and "actually caring about what they're doing" that matters. Tests are a tool to aid that. Tests don't sit in the driver's seat.
- mikekchar 8y agoYeah. To me "test driven" really means that I write code under the constraints that it has to make writing my tests sensible and easy. This turns out to improve design in a large number of cases. There are lots of other constraints you can use that tend to improve design as well (method size, parameter list size, number of object attributes, etc are other well known ones). But "test driven" is a nice catch phrase.
- corobo 8y ago> Except that's a really bad analogy. It's more like The response to every analogy ever made on the internet. Can we stop using them yet?
- carlmr 8y ago
- YeGoblynQueenne 8y agoThe problem with TDD is that a dedicated developer can always make a test pass- the how is another matter.
- celvro 8y agowhen(mockObject.getVar()).thenReturn(1); assertEquals(1, mockObject.getVar()); test passes boss!
- wutbrodo 8y agoYup, in static vs dynamic conversations, I invariably see someone dismiss the value of compiler enforcement by claiming that you should be writing unit tests to cover these cases anyway. Every time I say a silent prayer that I never end up working with the person I'm talking to haha.
- acroback 8y agoTDD need to die. This is a curse. There should be integration tests along with some property based tests and fuzzy tests. Usually catches a lot of things.Invest in monitoring and alerts too. TDD is like relying on debugger to solve your problem. Is debugger a good tool? yes,it is a great tool. But using it as an excuse to avoid understanding what happens under the hood is plain wrong. The problem lies in industry where software engineering is not given any value but whoteboarding and solving puzzles is. Software engineering is a craft honed over years of making mistakes and learning from them. You want code asap, kick experience engineers get codemonkeys in and get a MVP. Quality is not clever algorithm, but clear conscise logic. Code should follow the logic, not the other way around. Clear > clever.
- acdha 8y agoI’m sympathetic but this is too strong: what needs to die is dogma. TDD as a way of thinking about the API you’re writing is good but anything will become a problem if you see it as a holy cause rather than a tool which is good only to the extent that it delivers results.
- danellis 8y agoWhat about TDD requires not understanding the code?
- ddfx 8y agoI think TDD is the best way to develop (yet). Obviously tests are code, and if you write crappy highly-coupled tests you will end up with only much more messy code. This is a clear example of bad testing. The greatest advantage of TDD is in design, everything should be modular and easy to unit test, so you could: - reproduce bug and verify your bugfix in matter of ms with proper unit test - understand what code does - change and refactor code whenever you want You can tell from what is written that they are not following TDD. Redesign that codebase in an easy and clean to test design would require an exponential effort and time compared to have it done step by step, but it would be worth it
- iopq 8y ago
- posedge 8y agoI don't see how this is an argument against TDD. Apparently a whole slew of things went wrong in this project but that doesn't imply that testing is the cause of them.
- dleskov 8y agoTDD only works in conjunction with thorough peer reviews. Case in point: at my place of work, code and tests written by an intern can go through literally dozens of iterations before the check-in gets authorized, and even the senior engineers are not exempt from peer reviews (recent interns are especially eager to volunteer).