Re: Problem with linker
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Thu, 07 Jun 2007 10:48:42 -0400
Default parameters introduce all kinds of problems, especially when overloading comes into
play. Suppose I have
class Someting {
public:
Something(LPCTSTR = NULL);
Something(int);
}
you would think there is no problem, but Something() is ambiguous.
C# handles this by providing multiple overloads, e.g.,
Something();
Something(string);
Something(int);
(take a look at the huge set of library calls with all the various combinations of
parameters). While it is a bit more difficult to write all the overloads, there is no
problem with future extensions creating ambiguities because of default parameters.
Deterministic finalization is fairly important, *especially* with a GC involved. Consider
SomeClass() { open file here, exclusive }
~SomeClass() { close file here }
void SomeFunction()
{
SomeClass();
.. do things
}
with nondeterministic finalization that is handled by the GC, the following sequence will
fail:
SomeFunction();
SomeFunction();
because the second call tries to open the file, which is already open, and isn't closed
until the GC discovers the object is no longer in use. When the only resource is memory,
nondeterministic finalization doesn't matter, but when external state is involved, which
is independent of memory, the temporal relationship matters a lot.
joe
On Thu, 07 Jun 2007 14:12:12 GMT, MrAsm <mrasm@xxxxxxx> wrote:
On Thu, 07 Jun 2007 10:37:38 GMT, "David Ching"Joseph M. Newcomer [MVP]
<dc@xxxxxxxxxxxxxxxxxxxxxx> wrote:
He's doing a great job with C# and .NET, IMHO.
He's a great guy. I think he generally did a great job with C#, but miss
some C++ things like default parameters (there are none), and the
deterministic finalization clearly missed the boat.
Hi David,
I think that, if C# should have default parameters (which can be a
good thing), I hope they do that like Ruby and not like C++ (because
the C++ way is somehow limited IMHO), e.g.:
<CODE language="Ruby"
url="http://www.wellho.net/resources/ex.php4?item=r104/llen2">
# Note that you can default and
# calculate a value for a parameter
# in the method definition in Ruby
def ladlen(high, wide = high/4.0)
Math.sqrt(high * high + wide * wide)
end
</CODE>
For deterministic finalization, I think that with a garbage collector
there is less need for it than with C++. For "scarce" resources, I
think that 'using' could be OK.
MrAsm
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Problem with linker
- From: MrAsm
- Re: Problem with linker
- References:
- Re: Problem with linker
- From: MrAsm
- Re: Problem with linker
- From: Tom Serface
- Re: Problem with linker
- From: MrAsm
- Re: Problem with linker
- From: Tom Serface
- Re: Problem with linker
- From: MrAsm
- Re: Problem with linker
- From: Tom Serface
- Re: Problem with linker
- From: David Ching
- Re: Problem with linker
- From: MrAsm
- Re: Problem with linker
- From: David Ching
- Re: Problem with linker
- From: MrAsm
- Re: Problem with linker
- Prev by Date: Re: Invisible Window
- Next by Date: Re: CStdioFile ReadString Unicode ANSI File
- Previous by thread: Re: Problem with linker
- Next by thread: Re: Problem with linker
- Index(es):
Relevant Pages
|