Re: default parameters
- From: "Rudy Velthuis" <newsgroups@xxxxxxxxxxxx>
- Date: Tue, 26 Feb 2008 17:14:39 -0800
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
.
- Follow-Ups:
- Re: default parameters
- From: Peter Duniho
- Re: default parameters
- References:
- default parameters
- From: Christopher
- default parameters
- Prev by Date: Re: default parameters
- Next by Date: Re: default parameters
- Previous by thread: Re: default parameters
- Next by thread: Re: default parameters
- Index(es):
Relevant Pages
|