Something IsMissing - A Short Story
Here's a short story with an "Optional" twist and a surprising moral.
Flashback
VB6 supports optional parameters. The VB6 compiler is happy to see these parameters without the default value. We all know. In VB6, we could also check whether an optional parameter was passed by the caller or not of using the IsMissing method. But this method worked only on Variants. Why? Because, the other types of variables where automatically initialized to their default values. So, there is no way of checking whether the value passed is the default value or actual value.
Present day
Variants are disbanded from VB.NET. So, its buddy, the IsMissing method was also pushed out. Our short story does not end here. Here's the twist. VB.NET also supports optional parameters. We all know. VB.NET however does not support optional parameters without default values. We all know this too. What we may not know is C# (and possibly other languages that target the CLR) does not allow optional arguments. So, how does one program written with C# consume a method written in VB.NET declared with default parameters.
The answer is - That patient programmer must pass System.Reflection.Missing.Value to force the default value to be taken. Ofcource, this has to be done for all optional arguments in the method call and hence, can be really frustrating for a C# dev.
Moral of the storty
It is always better to use overloading than to use optional arguments. So, VB6 devs, please come out of your "Optional" habit. If you are addicted to Optional and are ticklish about overloading, then try limiting that addiction to Internal classes only ( Ahem…I mean Friends!)