3 ms·
I've had this discussion, and thought I would share a specific example of one case that to my mind highlights the issues. I had some horrendously complex code
by RiderOfGiraffes 16y ago
I've had this discussion, and thought I would share a specific example of one case that to my mind highlights the issues.
I had some horrendously complex code to compute the two roots of a quadratic, and someone came along and "tidied it up." They replaced my code with:
delta = sqrt(b^2-4*a*c)
a2 = 2*a
x0 = (-b+delta)/a2
x1 = (-b-delta)/a2
They were then horribly confused over why the tests started failing, the check-in was broken, and all hell broke loose in the development branch.
He put it back and all was well, then came to ask me about it. I explained about numerical stability, and all was well.
So with regards comments:
Pro: He would've known not to change the code, and it was complicated for a reason.
Con: He wouldn't've come to me to discuss why it was a problem, and hence wouldn't've learned about numerical stability.
Gripping hand: With a comment he would've known why, and the time wasted changing the code, testing, investigating and putting it all back would've been saved, and better spent learning about numerical stability, which he then had to do anyway.
I'm in favor of the correct use of comments, and YMWV as to what that means. Dogma is the enemy of true progress.