Re: default parameters

Tech-Archive recommends: Speed Up your PC by fixing your registry



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
.



Relevant Pages

  • Re: XSLT Dataset - need help by transform
    ... which do return an XmlReader. ... and took for granted all of its overloads returned void. ... Derek Harmon ...
    (microsoft.public.dotnet.xml)
  • Re: void and this
    ... Well, void doesn't quite work with metaprogramming, but it ... int foo ... You just wrote N overloads that currently require ... undoubtedly rubs most people. ...
    (comp.lang.cpp)
  • Re: void and this
    ... You use type traits to see if an argument is void or not. ... int foo; ... you could do c'tor forwarding very nicely: ... because it's too tedious to write the overloads. ...
    (comp.lang.cpp)
  • Re: Dose C#2.0 support optional parameters
    ... unnoticed by every reply is that only optional parameters allow for the use ... > means of overloading, facilitated by the compiler. ... > Actual function names of generated overloads are mangled/decorated similar ... > void Foo; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I create a programming language?
    ... > I'm not really at the stage of language design yet, ... int str_len; ... void interpret{ ... Opcode opcode; ...
    (comp.programming)