6 ms·
If you don't know what the code is supposed to do, how are you writing it?
by mbrock 11y ago
If 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.
- mbrock 11y agoI don't agree with "no sense whatsoever." Actually, TDD can be a very pleasant way to do this kind of exploratory programming, precisely because it's oriented around verifying expectations.
- lfowles 11y agoYep, any time I have an assumption about how code should work, that's a good starting point to write a test. Even if it's vaguey like "should not throw when given inputs X Y Z that I expect will be encountered"
- crdoconnor 11y agoThat's kind of a waste of time if you're only going to run it once and verification with a REPL or otherwise by hand is easy enough.
- lfowles 11y agoThat's assuming it works correctly the first time (I haven't had that experience often, even for "trivial" code :( ). Even for "run once" functions, I still use a few tests to develop them and make sure my expectations are correct. With a good framework, setting up a handful of unit tests takes just about as much dev time as running the function in a REPL.
- crdoconnor 11y agoOk, so let's say you were experimenting with the selenium library to see if you could scrape what comes out of skyscanner. What steps would you take?
- lfowles 11y agoI'm not clear on what the scope of selenium is or how it works, but for a general web scraper, I'd identify some targets I want out of skyscanner. Here's a quick googletest butchery for "I want to make sure my function returns flights for a known good flight search." TEST(SkyScanner, ListFlights) { flights = MyFlightScrapingFunction(LAX, AMS, date+1 month, 1 way, 1 adult) EXPECT_THAT(flights, SizeIs( Gt(0) ) EXPECT_THAT(flights, Each( AllOf( Field(&Flight::from, Eq(LAX)), Field(&Flight::to, Eq(AMS)), Field(&Flight::seats, Eq(1)) ))) } I feel that anything simpler ("is this possible with selenium?") is a documentation moment.
- barrkel 11y agoThe preference function (or oracle) can return a truth value without you necessarily having insight into its inner workings. People "know it when they see it" without necessarily being able to define it. So you write the code; expose it to a preference function / oracle, iterate, and hill-climb towards a local optimum. The revealed preferences may give enough information to make a creative leap off the local hill onto a large hill elsewhere - but it may not. After a solution has been found, then you can write tests.
- catnaroek 11y ago> The preference function (or oracle) can return a truth value without you necessarily having insight into its inner workings. Is this preference function implemented on a computer, or is it just a person giving you seemingly random answers in response to whatever you tell them? > People "know it when they see it" without necessarily being able to define it. That path leads to hell. > After a solution has been found, then you can write tests. what exactly would you test? Tests make sense when you want to check that your implementation conforms to a certain set of logical rules, but where exactly is the logic in the process you outlined?
- douche 11y agoWhere is the logic in most business logic? \s Seemingly random answers, which are not functionally pure (aka ask the same question, get the same answer) are par for the course
- barrkel 11y ago> > People "know it when they see it" without necessarily being able to define it. > That path leads to hell. That's why they pay us the big bucks. If people could define their problems well enough without iterative design, waterfall development would be a success story and all software would be outsourced to the lowest bidder.
- catnaroek 11y agoThat's wrong. It's perfectly possible to define your problem well, and still require an iterative process to find a good solution.
- bencollier49 11y agoI'd translate this as "don't use tests for proof-of-concept code". At least not when success is easily observable.
- jacques_chester 11y agoIn XP settings this is called "spiking" and is recognised as an entirely legitimate tactic. The point of spiking is that you don't know enough to TDD. You are outside the sweetspot where TDD is tractable. The key to spiking is that once you come with a plausible approach, or have a conceptual breakthrough, you stop, backtrack and then switch back to TDD. Like everything else in mature software engineering, agile or classical, it requires sustained discipline.
- bencollier49 11y agoInteresting. I've found myself drawn into XP-style delivery repeatedly, probably because I tend to work closely with clients who have rapidly shifting or unknown requirements.
- jacques_chester 11y agoWe have a London office. Email me and I can probably ask if they'll let you visit. (They'll try to recruit you, but TANSTAAFL).
- deleted 11y ago[deleted]