Re: default parameters
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Tue, 26 Feb 2008 17:47:17 -0800
On Tue, 26 Feb 2008 17:14:39 -0800, Rudy Velthuis <newsgroups@xxxxxxxxxxxx> wrote:
[...] 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-
Well, that's an interesting perspective (duh :) ). However, I'm not sure why a default value for a parameter _must_ be "burned into the call site". I realize that's how it's done in C++, but C# could have instead used the default value syntax to create implicit overloads. In that way, the default value would be part of the implementation instead.
Of course, that adds some hidden complexity to the language. It would be one more thing where C# looks a lot like C++ but then does something not quite the same as C++, which could lead to confusion. And of course, this all goes back to the fact that an explicitly written overload does the same thing, so it's not like functionality is missing.
But that would have been an option, if trying to address that latter point of his. I'm disappointed he didn't touch on that in his talk.
Pete
.
- References:
- default parameters
- From: Christopher
- Re: default parameters
- From: Rudy Velthuis
- default parameters
- Prev by Date: Re: Only allowing alphanumeric characters and '_' and '-'
- Next by Date: Re: How do I Invoke a ListViewItem thread?
- Previous by thread: Re: default parameters
- Next by thread: Re: default parameters
- Index(es):
Relevant Pages
|