One thing that really erks me is the lack of default parameters in C#,
such that I have to write 16 versions of a constructor in C#, one for
every permutation of default params in a C++ constructor, when
migrating.
If you are handling all possible permutations of optional parameters, then
you're going to have almost as many constructors in C++ as you'd required
in C#. Default values don't address permutations...they simply allow you
to leave out the last N parameters for the function.
While I know that C# does not support default parameters,
can someone explain the reasoning behind why it does not?
I can't tell you the actual reason why not. And I admit, the first time I
tried to use a default parameter in C#, I had a "huh?" moment and like
you, felt it was a bit arbitrary to leave that feature out.
However, since that moment, I've done a lot more C# programming and have
come to see C# as a language with relatively simple syntax, with the
simplicity of the syntax being a positive thing. It can be powerful, but
most of that power comes from utilizing the simple parts in powerful ways.
I think it's entirely possible that the C# designers felt that allowing
default values for parameters would overcomplicate the language
unnecessarily. After all, the language needs to support overloading
anyway, and overloading is not only a reasonable alternative to default
values, it allows you do implement more complex default behavior than a
default value would.
Not that supporting default values would prevent you from doing that
otherwise. In fact, I look at default values as being a sort of short-cut
for declaring multiple overloads. It's just that the utility of default
values is relatively minor as compared to the utility of supporting
overloads.
Sometimes I find myself missing default values for parameters. I think to
myself "would it really have been that hard or detrimental to include
this?"
But it's never really that big of a deal. Writing additional overloads
doesn't really create that much overhead. Or put another way, if you've
got a situation where the requirement to write overloads causes you to
have to write 16 _additional_ methods that you wouldn't have otherwise,
there's a really good possibility that your interface has gotten out of
hand and needs to be redesigned anyway.
Pete