Hacker News new | past | comments | ask | show | jobs | submit login

We have, in the past, had code that computes the roots of quadratic equations in what appears to be a needlessly complex way. It's deliberately uncommented, and deliberately has an innocuous name.

When a newer employee comes across the code they often "simplify" it using the quadratic formula they know so well, and which they believe always works.

The tests go red.

They roll back and look to try to understand. Eventually they either work it out, or they come and ask for advice. We work through the test case with them, and point out just how important it is that:

* There are tests;

* Routines have useful and enlightening names;

* If the code is complex, there's probably a reason, although not always;

* Sometimes a comment might be useful.

It's proven to be a really useful learning experience, and gets people up to speed very quickly with things. It's then left again as a learning experience waiting to happen.

Of course, this can only work in a culture where people work constructively to understand what's going on, and support each other - a place where it's OK to say that you don't understand something, and know that others will work with you. I've been in places where this wouldn't work.

All in all, I've been lucky.

The tests, by the way, only have a moderate size b, but have a very small a. In this way b^2-4ac is very close to b, so one of the solution paths is subtracting nearly equal quantities, getting small rubbish. But then you go on to divide by a very small number, giving big rubbish.

The geometric interpretation is that the parabola is very, very flat, so if you move it even the tiniest amount up or down the roots move very far, very fast.

It's a useful example - my thanks to johndcook for the write-up.







Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: