473,772 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Poll" Has C# Generally Replaced C++

Is it your general opinion that C# is generally designed/intended/ready to
replace C++? I know the answer is not black and white but please repond YES
or NO (add any comments if you would like)

I just thought it might be interesting to get a tally. This is related to a
previous thread. So far we have two NOs from "aa" and Bo Persson.

--
Greg McPherran
www.McPherran.com
Dec 10 '05
71 3184
"Greg" <gm@mcpherran.c om> wrote in message
news:94******** *************** ***********@mic rosoft.com...
"Bo Persson" wrote:

std::vector<int > x;


std::vector<int > x;

vs.

int[] x;

I rest my case :-)


std::vector<int > x;

vs.

System.Collecti ons.Generic.Lis t<int> x;

Better to compare apples to apples...

-cd

Dec 12 '05 #21
"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:OX******** ******@TK2MSFTN GP11.phx.gbl...

Still not apples to apples - how 'bout:

std::vector<int > x;

vs.

System.Collecti ons.Generic.Lis t<int> x = new
System.Collecti ons.Generic.Lis t<int>();

-cd
Dec 12 '05 #22

"Bo Persson" <bo*@gmb.dk> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
<SNIP> Ok, then count me in with the "People".
Bo Persson


Count me as thinking just like Bo does.

-Michael Viking
Dec 12 '05 #23
Greg wrote:
e.g. int[] x; v.s. int x[];
int[] x;
vs
cli::array<int> x;

I agree, the original designers of C could have separated the type a
little bit better. But nobody uses types like int[] anymore for function
arguments -- you simply pass int*.
C# has the advantage of practical "non-rushed" thinking in its design.


And yet it doesn't support such basic features as constants and constant
member functions. No destructor (!!!) means no RAII, which is big
problem when an object holds a resource. You can't create a class on the
stack. No operator overloading, no templates. You can't even declare a
pointer and increment it. And so on, I could continue.

Tom
Dec 13 '05 #24
JAL
This is as expected in a garbage collected runtime, but you can still do
deterministic cleanup:

http://www.geocities.com/Jeff_Louie/oop26.htm

"Tamas Demjen" wrote:
No destructor (!!!) means no RAII, which is big
problem when an object holds a resource. Tom

Dec 13 '05 #25
JAL wrote:
"Tamas Demjen" wrote:
No destructor (!!!) means no RAII, which is big
problem when an object holds a resource. Tom
This is as expected in a garbage collected runtime,


It's really not a consequence of the runtime being garbage collected, but
rather a consequence of the by-reference way in which objects are handled in
C# (or Java). The lifetime of the object is de-coupled from the lifetime of
the reference by the indirection. This can be a "Good Thing" if the object
contains no resources other than memory, but it's a detriment when the
object holds other kinds of resources.
but you can still do deterministic cleanup:

http://www.geocities.com/Jeff_Louie/oop26.htm


Yes you can. The problem is, you have to remember to do it. In C# it's a
coding idiom. In C++ it's the natural language semantics.

-cd

Dec 13 '05 #26
JAL wrote:
This is as expected in a garbage collected runtime, but you can still do
deterministic cleanup:

http://www.geocities.com/Jeff_Louie/oop26.htm


I don't want that. try/catch can't do

std::vector<boo st::shared_ptr< Resource> > items;

I need my destructor, not only for deterministic cleanup in a scope, but
also for deterministric cleanup in containers. If you store resources
that require destruction (non-memory-only resources) in a container, you
still want to make sure that when the container goes out, all its items
go out automatically. Maybe if you program in a fully managed
environment you don't use destructors that often, but I essentially wrap
unmanaged code to managed interfaces, and therefore all of my classes
requires Dispose() to release unmanaged memory in a timely manner. You
could say they'll eventually be garbage collected, but I'm saying it's
too late. Some resources are very critical and must be destroyed
deterministical ly, and unmanaged memory must be deallocated as soon as
possible too.

Just imagine storing high resolution color images wrapped in a very thin
managed class. I don't care if the garbage collector doesn't kick in for
a while for the 16-byte unmanaged part, but my 50 MB unmanaged data had
better be deallocated when they're not used anymore. I can't wait until
the garbage collector runs out of managed memory, because my unmanaged
memory will run out much earlier. My example shows that a single missed
call to Dispose can be just as catastrophic in the managed world as it
is in the unmanaged world, except the unmanaged world has tools
(boost::shared_ ptr) to deal with that situation. And I believe C++/CLI
is prepared to deal with those cases too. C# is not. Correct me if I'm
wrong.

You could say I'm just spoiled by modern C++ and boost, but C# is a step
behind from this point of view, and .NET itself is a step behind for not
supporting const correctness too. It's also a step forward for
properties, events, reflection and self-contained packaging (managed
assembly) support.

Tom
Dec 13 '05 #27
Greg wrote:
Is it your general opinion that C# is generally designed/intended/ready to
replace C++? I know the answer is not black and white but please repond YES
or NO (add any comments if you would like)

I just thought it might be interesting to get a tally. This is related to a
previous thread. So far we have two NOs from "aa" and Bo Persson.


Yes and no.

IMHO C++ - C++/CLI and C# can be used very effectively together and both
languages have their pros and cons.

What about if the C# compiler could freely mix both languages in a
single project e.g. something like 'extern "C++" in C# ;-) and directly
call the C++/CLI code without using an intermediate DLL or linker tricks ?

If additionally C# would have RAII I would be perfectly happy about this
combination.

To be real, I think both languages will coexist for a very long time.
Only if the basis, the operating system and it's main interfaces will be
managed code too and if the native MSIL compiler will be available I
think more and more code will be written in plain C#.

Currently I think C# has another focus than replacing C++. But this may
happen some day.

Andre
Dec 13 '05 #28
int[] x;

x has all the methods of ICollection and Array. So I think int[] x is apples
to apples.

--
Greg McPherran
www.McPherran.com
"Carl Daniel [VC++ MVP]" wrote:
"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:OX******** ******@TK2MSFTN GP11.phx.gbl...

Still not apples to apples - how 'bout:

std::vector<int > x;

vs.

System.Collecti ons.Generic.Lis t<int> x = new
System.Collecti ons.Generic.Lis t<int>();

-cd

Dec 13 '05 #29
JAL
Then you should like C++/cli which implements the using construct within the
language semantics as long as the ref class is constructed "on the stack".

"Carl Daniel [VC++ MVP]" wrote:

Yes you can. The problem is, you have to remember to do it. In C# it's a
coding idiom. In C++ it's the natural language semantics.

-cd

Dec 14 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.