DEV Community

Discussion on: Do you write tests when exploring a new idea?

Collapse
 
sargalias profile image
Spyros Argalias

It all depends. I would categorize "exploring ideas" as "prototype-like code". If you spend time writing tests, just to delete all the code after, you might waste more time overall compared to not writing tests.

  1. When I do this type of coding, I generally don't write tests until I know I'm happy with the direction I'm going at and believe that I'm likely to keep the code.
  2. It's definitely an intuition / feeling thing. I would say, it depends on how helpful you find tests during development. If you find them very helpful, consider writing them earlier. There's also the risk of wasted time in case you throw away all the code. Overall, if in doubt, I lean towards writing tests (I find TDD very helpful). At the end of the day, it's an optimisation thing between those two: Development efficiency gained from writing tests vs potential time wasted depending on how likely it is that you'll throw away the code.
  3. I feel like this is a separate topic. If it's a proper project, I add the kind of configuration you mentioned very early, as soon as I feel it's helpful. If the whole project is a prototype, meaning that you might delete the entire project later, then maybe it's worth starting with a pre-made config or boilerplate instead and customising later if needed.
Collapse
 
alchermd profile image
John Alcher

Thank you for your insight. I agree on all your points, perhaps this is just a matter of deciding when to pull the trigger. I guess I just get too attached to my prototypes. I have this habit of hacking on top of a working prototype until it's "good enough" when I should have extracted out the core logic and restart with a solid base.

Collapse
 
sargalias profile image
Spyros Argalias

Fair enough. I think restarting or refactoring the prototype code would work as long as the code quality is good in the end, whatever works for you. Since I like TDD a lot, just like you, I tend to restart. However, I keep the prototype code nearby for reference and / or even copy some parts of it.