November 3, 2004

Code Funerals

http://www.msnbc.msn.com/id/6397274/

Why didn't I think of this? I would have loved to do this to some of the programs I've worked on.

The worst was thanks to a compiler transition. We kept getting really weird errors that we traced to a function that was, shall we say, prematurely optimized.

It had lots of code like this in it...

f++ = g(++f,++f,--f, f++);

Since the order that pre-increments and post-increments are handled is not stated in the C++ specification, each vendor, and on occasion, different products from the same vendor, handle them in different orders. In the first compiler, they were handled from right to left. In the second compiler, they were handled from left to right. We ended up not changing compilers for the project.

Code like that makes me grateful that VB.NET does not have pre/post-increment operators. And if you ever find yourself writing code like this, please do all of us a favor and stop. I'd rather deal with some temporary variables and have code that I can easily trace and understand, thank you very much.

No comments: