Re: Why can't overloads take into account the return type.
- From: "Michael C" <mculley@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 16 May 2005 09:05:51 +1000
"Daniel O'Connell [C# MVP]" <onyxkirx@xxxxxxxxxxxxxxxxxxxxx> wrote in
message news:%23le$D74VFHA.3184@xxxxxxxxxxxxxxxxxxxxxxx
> Now, you add into that a requirement to know the type of the variable the
> return type is going to be assigned to or the parameter type it will be
> passed to. This forces the compiler to have to be able to see
>
> int x = Parse(something);
The compiler is going to need to know the return type anyway. I don't see it
much different from:
Parse(Something, ref x);
> The method call is not individually resolvable, it becomes an expression
> that means nothing concrete without being contained within another
> expression(I do not believe this issue exists *anywhere* else in the
> language, but I'm not certain). The compiler is harder to write, the
> language harder to learn. Bam, instant complexity at the base level of the
> compiler.
Overloading makes the language harder to learn, as does inheritance and
interfaces, we'd better leave those out too. :-)
> Now, lets take this a step further and produce a few difficult or
> impossible to resolve scenarios.
>
> Given:
> int Parse(string value);
> double Parse(string value);
>
> int Calc(int value);
> double Calc(double value);
>
> double d = Calc(Parse("15")):
>
> When the compiler takes a look at the call to Parse it cannot resolve what
> overload to call. The compile rmust then take a look at the parameter type
> for Calc, which also cannot be resolved atomicall ywithout knowing the
> resolved return type of the Parse call, so you have yet another unresolved
> method. You step back a little farther and finally discover an assignment
> meaning you can determine the desired return type of Calc, and in this
> example, determine which overload of Parse must be called. However,
> considering the compiler without return type overloads would have had no
> trouble doing this, what is the cost in complexity?
But it can do it and it makes sense to the programmer for it to be double
all the way through.
> Is this really as simple as you think it is? I've not even started on the
> possible issues with generics and anonymous methods and the language
> itself is already considerably more complex. Realistically implementing
> return type overloading, IMHO, requires a mechanism to manually select the
> override instead of relying on automatic selection that ignores casts and
> converstions.
I'm sure it can get complex but in any case it can't resolve the call it
should just say so. Programmers would know to specify the return type in the
necessary cases. Maybe something like double d = Calc((double)Parse("15")):
could be used.
>
>
.
- Follow-Ups:
- Re: Why can't overloads take into account the return type.
- From: Daniel O'Connell [C# MVP]
- Re: Why can't overloads take into account the return type.
- From: Steve Walker
- Re: Why can't overloads take into account the return type.
- References:
- Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: mdb
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Alan Pretre
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Alan Pretre
- Re: Why can't overloads take into account the return type.
- From: John B
- Re: Why can't overloads take into account the return type.
- From: Chris Priede
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Daniel O'Connell [C# MVP]
- Why can't overloads take into account the return type.
- Prev by Date: Re: Help with class design
- Next by Date: Re: How to enumerate open files using DirectoryServices
- Previous by thread: Re: Why can't overloads take into account the return type.
- Next by thread: Re: Why can't overloads take into account the return type.
- Index(es):
Relevant Pages
|