I have just found a piece of code which is probably about 3 years old. This is active project that I work on it almost day by day.
The method below is a helper utility for unit testing (and for that matter is used only for unit testing) to compare 2 value wrapped in IElement (Enterprise Core Objects).
Do you see this “Implementation bug: Invalid logic in this method.”. Now, do you see the ApplicationException? That is ridiculous!
If I would ever get this exception i would think: System found a bug for me. It must be AI.
Instead of writing this stupid message wrapped in the system exception the last lines of the method should just look like:
The method below is a helper utility for unit testing (and for that matter is used only for unit testing) to compare 2 value wrapped in IElement (Enterprise Core Objects).
private static bool CheckOclEqual(IElement expectedElement, IElement actualElement) { if (expectedElement == null && actualElement == null) return true; if (expectedElement == null) return false; if (actualElement == null) return false; object o1 = expectedElement.AsObject; object o2 = actualElement.AsObject; if (o1 == null && o2 == null) return true; if (o1 != null) return o1.Equals(o2); if (o2 != null) return o2.Equals(o1); throw new ApplicationException("Implementation bug: Invalid logic in this method."); }
Do you see this “Implementation bug: Invalid logic in this method.”. Now, do you see the ApplicationException? That is ridiculous!
If I would ever get this exception i would think: System found a bug for me. It must be AI.
Instead of writing this stupid message wrapped in the system exception the last lines of the method should just look like:
if (o1 != null) return o1.Equals(o2); return o2.Equals(o1); // No need in that stupid exception at all hereWell, nothing to say on this except:
- shame on me;
- it made me smile;
- strangely, I have never got this exception :);
- it overlived .NET 1.1, .NET 2.0, .NET 3.0 and jumped straight into .NET 3.5;
- it is not yet a legacy code.