Spike Solutions
Note
Programmers
We perform small, isolated experiments when we need more information.
You’ve probably noticed by now that XP values concrete data over speculation. Whenever you’re faced with a question, don’t speculate about the answer—conduct an experiment! Figure out how you can use real data to make progress.
That’s what spike solutions are for, too.
About Spikes
A spike solution, or spike, is a technical investigation. It’s a small experiment to research the answer to a problem. For example, a programmer might not know whether Java throws an exception on arithmetic overflow. A quick 10-minute spike will answer the question:
public class ArithmeticOverflowSpike {
public static void main(String[] args) {
try {
int a = Integer.MAX_VALUE + 1;
System.out.println("No exception: a = " + a);
}
catch (Throwable e) {
System.out.println("Exception: " + e);
}
}
}
No exception: a = -2147483648Note
Although this example is written as a standalone program, small spikes such as this one can also be written inside your test framework. Although they don’t actually call your production code, the test framework provides a convenient way to quickly run the spike and report on the results.
Performing the Experiment
The best way to implement a spike is usually to create a small program or test that demonstrates the feature in question. You can read as many books and tutorials as you like, but it’s my experience that nothing helps me understand a problem more than writing working code. It’s ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access