The ‘what if’ technique, a simple tool to become a better software engineer

Andrea Capuano
Analytics Vidhya
Published in
4 min readJul 16, 2021

--

As years went by I have spent countless hours developing code, and one of the simplest tips that helped me over time is what I like to call the ‘what if’ technique.

The “what if” approach is quite straightforward: every time you finish doing something, you ask yourself “What if X happens”. This can be applied to programming, to system design and many other places.
The concept itself is not something revolutionary, however it becomes hugely impactful if you make it a habit. It seems so simple and yet so many production disasters could be avoided if we have this one simple habit, ask ‘what if’ at the end of that final line of code.
Let’s make some examples.

Suppose you need to write a method to reverse a string only if it begins with a number and leaves it as-is otherwise.

Let’s write the method and a couple of unit tests for it:

Now, let’s start with the ‘what ifs’ and see how they map to unit tests:

  • What if the input string is None
  • What if the input string is not a string
  • What if the input stringis empty

--

--

Andrea Capuano
Analytics Vidhya

Software Engineering, Artificial Intelligence, Random thoughts