Scientific Programming “Don’ts” – Don’t leave confusing code undocumented

Sometimes your code does something not trivial to fix a problem that isn’t obvious. For example, in one place someone was having some rounding issues, so we found this gem in the code:

double *pf = &f;
(*(long long *)pf) += 8;

The only comment there was “solve rounding issues”. We’ve encountered this code when it actually caused rounding issues. The person who wrote this has been gone for a long time, and we had to figure out what rounding issues he was having, and why this fixes them. Until this day we are not 100% sure why this code was written this way.

Leave a Comment