DEV Community

Cover image for TDD x Coding Challenges
Bruno Noriller
Bruno Noriller

Posted on • Originally published at linkedin.com

TDD x Coding Challenges

I hate coding challenges. And with that out the way...

I mean, I understand what they bring to the table, depending on where you work it’s definitely a way to train. But most of the time, it’s either a chore you need to learn and train to do or a fun brain teaser you do in your free time.

But someway, somehow for reasons unknown to me... it’s something many hate and yet is the industry standard... want a job in tech?
Use this terrible online (and not your) IDE everyone will hate to answer the cumulative weight of a watermelon person problem that has 10 million watermelons where its size changes in a Fibonacci pattern.


My challenge (pun intended)

What I wanted: Can you use, explicitly, TDD to solve coding challenges?

What I found: depends. (the default programmer response)

While you can (and should) use TDD even without using TDD.
(basically, you go through the red-green-refactor cycle, just without writing tests.)

Why TDD might not the right tool for the job:

  • You can end up “wasting” time (especially when it’s a timed challenge) on things that are not important to the test at hand.
    • many challenges say that the input doesn’t need to be validated
    • you already know the minimum/maximum values possible
  • You already have test cases.
    • you might not know what they are (and some platforms even hide if you’re passing everything or not... not sure why...) so, do you even need to actually write the tests?
  • Many challenges are self-contained.
    • most of what you have to make could be made in a line and not in multiple functions/classes.
    • if you start with a wrong abstraction or data structure, all the buildup you’ve made goes to the “trash”.

Is it useless then?

I’m not saying you’re not gonna get a solution using TDD, you will.

Most likely, when you’re totally lost, TDD will help you reach a solution...

It just might not be the “BEST” solution, the solution that will pass all tests (especially the time/space complexity ones).


Now with you!

What is your experience with coding challenges?

Do you have an alternative for solving them?

So far, the best advice I got and that I can give you is the one you’ll probably see in many games out there (with pun intended): “git gud”.


Cover Photo by Jukan Tateisi on Unsplash

buy me a coffee

Top comments (0)