Re: default parameters



Christopher wrote:

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. While I know that C# does not support default parameters,
can someone explain the reasoning behind why it does not?

http://msdn.microsoft.com/msdntv/transcripts/20040624csharpahTranscript.aspx

<<
Hejlsberg:

Okay. The question is, Why don?t we have default parameters? I think
there are a couple of reasons. First of all, they?re somewhat
duplicative of overloading. I mean you can do the same with
overloading, and which is indeed what people do today, but yes, you?re
right. It?s more typing for sure. I think the other one is subtler, and
in retrospect maybe not as important as I thought. Originally in the
language design are- our issue with default parameters is that they
burned the default into the call site as opposed to leave it up to the
implementation. If you do overloads, let?s say you have void f, and
then, let?s say, you have void f of index, for example, and void f of
index is where the work happens, right? Then in this guy here, you
simply say echo 5, because your default is 5. When the user calls f, it
is up to you to change- you can change what your default is later in v2
of your API. When you have a call f somewhere, this by the compiler is
translated into f of 5 in the call site,-

-because it just copies that value. Now you can never change the
default. This gives you more flexibility, but- and I thought that that
was important. Perhaps it?s not all that important, but-


--
Rudy Velthuis http://rvelthuis.de

"Physics is not a religion. If it were, we'd have a much easier
time raising money." -- Leon Lenderman
.



Relevant Pages

  • Re: Copy Constructor Craziness
    ... There is no copy constructor involved at all. ... because I don't see any justification for this autogeneration. ... If you're overloading a mutator, there needs to be a copy ...
    (comp.lang.perl.misc)
  • Re: still crabby about copy constuctor craziness
    ... When the copy constructor gets ... or if a mutator has been explicitly overloaded. ... newest version explicitly overloads them. ... > no such thing as a copy constructor, and no operator overloading. ...
    (comp.lang.perl.misc)
  • Re: [MSH] how to list constuctor overloads
    ... Void .ctor ... > I did know that I needed an attachement object first (fits nice in the ... > new-object: Constructor not found. ... > Encoding contentEncoding, String mediaType), static System.Net.Mail.Att ...
    (microsoft.public.windows.server.scripting)
  • Re: LoadControl() and Constructor Parameters
    ... void Init. ... Page_Init phase as because if you do this on say, Page_Load, the control ... non-default constructor to work. ... also make the _Subcategory a public field and rename it to Subcategory, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: IsNumber function
    ... I've never cared what type of data gets passed to it in a VBA function and have used a variant...which basically is what you did there with the overloading. ... The disadvantage of this is that widening also takes system resources and in my opinion is poor practice, since it creates code that can be hard to read or debug. ... Stefan's code also used widening (from auto-boxed primitives up to Object) and you see that folks are complaining about it. ... I also added a trick where I declared the default constructor private, thus preventing the user from accidentally calling a constructor that did nothing. ...
    (comp.lang.java.help)