|
|
|
|
|
by jph
3077 days ago
|
|
For example, here's one way to write a test that sufficiently explains "gets within a certain error margin of the correct answer yet is much much faster than the naive way". Using Ruby and its built-in minitest gem: 1. Write a test that does minitest assert_in_epsilon(x,y,e) 2. Write a minitest benchmark test that compares the speed of the fast function with the speed of the naive function. Notice the big advantage for long term projects: if the hack ever ceases to work then you'll know immediately. This actually happens in practice, such as math hacks that use 32-bit bit shifts that started failing when chip architecture got wider. > no one on the Quake 3 team can remember who wrote it Exactly. We have the code file, but not any documentation separate from the code, such as notes, plans, attempts, reasoning, etc. |
|
I agree with you that it can be tested. But it doesn't explain anything about why it works, or what methods the author tried that didn't work as well. If you ever had to make it faster, or make it work better on different hardware, you'd be starting from scratch again.