Re: Why can't overloads take into account the return type.
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Tue, 17 May 2005 00:33:01 +0100
Michael C <mculley@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
> news:MPG.1cf248cf4c9d689698c119@xxxxxxxxxxxxxxxxxxxxxxx
> > Out of interest, why do you think that is? You're not the first person
> > to come up with this idea, so if it's such a good idea, why do you
> > think it hasn't made it into any languages?
>
> For some reason language writers seem to like to keep things consistant with
> previous languages.
Given how many experimental languages there are, that seems unlikely to
me. There are plenty of languages which try lots of different things,
and the best concepts usually work their way into the mainstream
eventually. I think there's a good reason for overloading by return
type not making it - it adds too much complexity for too little
benefit.
> > While I can see it would allow us to get away from having lots of
> > methods with different names but the same parameter types, that's the
> > *only* advantage I can see,
>
> That's the only advantage of the current overloads.
The difference is how often that's useful compared with how often
overloading by return type would be useful though. Look at all the
examples of overloading by parameters in the framework, and then think
of how many places overloading by return type would really be useful.
Places I can think of:
DataReader
Convert
BitConverter
Stream
TextReader
BinaryReader
Marshal
Frankly, in all those places I think having the instantly readable an
unambiguous calls is often more of a blessing than a curse. Arguably
having more explicit alternatives to overloading for writing in some of
the above would be a better way to improve things - and at no language
complexity cost.
> > and that situation comes up pretty rarely
> > in my experience. I don't think it justitifies making the language
> > significantly more complicated.
>
> I don't see it as much greater complexity. For example if they'd
> implemeneted it for the datareader you might have to write it as
> (int)reader.Value(1) instead of reader.GetInt(1). If the compiler complained
> in any situation that was not dead obvious then it could work quite well.
It's a fundamentally more complicated language though, as the type of
an expression would depend on its context in a way in which it simply
doesn't now.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: Why can't overloads take into account the return type.
- From: Helge Jensen
- 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: 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]
- 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]
- 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: Jon Skeet [C# MVP]
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Why can't overloads take into account the return type.
- Prev by Date: How can I create a combo box with no boundary and arrow indicator?
- Next by Date: Re: remove new line in constant
- 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
|