DEV Community

John Alcher
John Alcher

Posted on

Do you write tests when exploring a new idea?

Hi!

I've been toying with a new project idea and have spent half a day doing exploratory programming to see how the different components would come together. I did cover a lot of ground, and in fact I'm probably going to pursue this project after a few more rounds of exploration.

This is in contrast to my usual workflow where I follow rigorous TDD. Now I find myself asking this question: when would be a good time to stop writing code, do some housekeeping, and start to build a test suite?

If you have had a similar experience before, I'm very curious on how you approached this scenario.

  1. Do you follow TDD, perhaps a lighter version, when exploring new ideas?
  2. If not, when do you start writing tests for the validated idea?
  3. Either way, at what point of these kinds of projects do you start configuring the "nice to haves" (linter config, coverage frameworks, pre-commit hooks etc)?

I'm really eager to hear your thoughts. Stay safe!

Top comments (4)

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.

Collapse
 
raul1991 profile image
cafebabe1991

Guilty of not doing that. 😰😄