Today I bring to you… another silly compiler quirk! Read on for the silliness.
I have been vigilant countless times regarding this and, after hundreds of successes, finally failed to be vigilant enough. You see, I often do a “search and replace” operation while refactoring. This week I refactored some common computation of the factor to convert from degrees to radians (PI/180) and ended up with this:
public static const DEG_TO_RAD:Number = DEG_TO_RAD;
That was the result of me properly adding the constant and then improperly replacing it with itself. This ends up compiling like this:
public static const DEG_TO_RAD:Number = NaN;
This is because DEG_TO_RAD is NaN before it is assigned any value. As is seemingly par for the MXMLC course, the compiler gave no error or warning. I then used the NaN value in some physics computations and the NaN value propagated through until all of the objects did a disappearing act. I was vigilant so many times before, but the lesson is to be even more vigilant!