"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 | | | | re: "Poll" Has C# Generally Replaced C++
By the way my vote is YES even though I know C++ can have advantages and is
still valuable/required for many purposes.
--
Greg McPherran www.McPherran.com
"Greg" wrote:
[color=blue]
> 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[/color] | | | | re: "Poll" Has C# Generally Replaced C++
"Greg" <gm@mcpherran.com> wrote in message
news:EE1D679B-952E-4B99-807E-C7D4A2D2E1A8@microsoft.com...[color=blue]
> 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)[/color]
No, it is not.
In a few years it may be the language most often used to _build_
applications for Windows, but the operating system and its drivers will
continue to be written in C or C++ for the near term at least.
Regards,
Will | | | | re: "Poll" Has C# Generally Replaced C++
Greg wrote:[color=blue]
> 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.[/color]
No. C# is a language designed, intended and ready to replace Java (and well
on it's way to doing so).
C++ is still better at nearly all the things C++ has always been better at.
-cd | | | | re: "Poll" Has C# Generally Replaced C++
"Greg" <gm@mcpherran.com> wrote in message
news:EE1D679B-952E-4B99-807E-C7D4A2D2E1A8@microsoft.com...[color=blue]
> 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[/color]
From a pure language point of view....
Designed & Intended to: NO
Ready to: NO
Some might say it's "ready to", but I guess this is only a personal
interpretation and only reflects their own requirements. There are simply
too many problem domains that aren't covered yet (although, this is not
strictly a language issue) , and I don't even consider the lack of platforms
availbility.
Willy. | | | | re: "Poll" Has C# Generally Replaced C++
5 NOs and only one YES (mine).
I guess my next question is then why would Microsoft call it C# which is:
C++
++ ?
The implication is that C# is to C++ as C++ was to C.
--
Greg McPherran www.McPherran.com
"Greg" wrote:
[color=blue]
> 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[/color] | | | | re: "Poll" Has C# Generally Replaced C++
Hi Greg![color=blue]
> 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.[/color]
Your question is a bit confusing...
You need to ask the "right" question to get the "right" answer!
For example: Will C# replace C++ in some small areas like UI?
--
Greetings
Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/ | | | | re: "Poll" Has C# Generally Replaced C++
No. C# is really VB with curly braces. C++ is a very different language. | | | | re: "Poll" Has C# Generally Replaced C++
For application programming C++ seems to be losing some ground according to
InfoWorld's Developer's survey:
java +34%
C# +23%
C/C++ -3%
"Greg" wrote:
[color=blue]
> 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[/color] | | | | re: "Poll" Has C# Generally Replaced C++
"=?Utf-8?B?R3JlZw==?=" <gm@mcpherran.com> wrote in news:92F79F27-998F-4CF7- 982D-F6157BEA2931@microsoft.com:
[color=blue]
> 5 NOs and only one YES (mine).
>
> I guess my next question is then why would Microsoft call it C# which is:
> C++
> ++ ?
>[/color]
Perhaps your next question should really be will C++/CLI replace C#? :)))) | | | | re: "Poll" Has C# Generally Replaced C++
"JAL" <JAL@discussions.microsoft.com> skrev i meddelandet
news:90C3BA77-7AAC-49EF-ADF7-A7303063B0D0@microsoft.com...[color=blue]
> For application programming C++ seems to be losing some ground
> according to
> InfoWorld's Developer's survey:
>
> java +34%
> C# +23%
> C/C++ -3%[/color]
And they can't differentiate between the languages either. Who knows,
perhaps this means C -10%, C++ +7%?
Bo Persson
[color=blue]
>
> "Greg" wrote:
>[color=green]
>> 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[/color][/color] | | | | re: "Poll" Has C# Generally Replaced C++
JAL wrote:[color=blue]
> For application programming C++ seems to be losing some ground
> according to InfoWorld's Developer's survey:
>
> java +34%
> C# +23%
> C/C++ -3%[/color]
I would suspect a poll in InfoWorld to be very highly skewed towards IT-shop
development and not representative of commercial application development
which is still dominated very strongly by C++.
-cd | | | | re: "Poll" Has C# Generally Replaced C++
William DePalo [MVP VC++ ] wrote:[color=blue]
> "Greg" <gm@mcpherran.com> wrote in message
> [...]
> No, it is not.
>
> In a few years it may be the language most often used to _build_
> applications for Windows, but the operating system and its drivers will
> continue to be written in C or C++ for the near term at least.[/color]
And yet Microsoft experiments with a research operating system written
in C#.
[color=blue]
> Regards,
> Will[/color]
Regards,
Andre | | | | re: "Poll" Has C# Generally Replaced C++
On Sat, 10 Dec 2005 08:55:03 -0800, Greg wrote:
[color=blue]
>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)[/color]
No.
It was designed to compete with Java, not C++. A different horse on a
very different course.
--
Bob Moore http://bobmoore.mvps.org/
(this is a non-commercial site and does not accept advertising)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
Do not reply via email unless specifically requested to do so.
Unsolicited email is NOT welcome and will go unanswered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ | | | | re: "Poll" Has C# Generally Replaced C++
"Andre Kaufmann" <andre.kaufmann.bei@t-online.de> wrote in message
news:e6XuDSo$FHA.1032@TK2MSFTNGP11.phx.gbl...[color=blue]
> And yet Microsoft experiments with a research operating system written in
> C#.[/color]
Yup. I've seen at least a couple of videos on MSDN's Channel 9 on the
subject of ongoing research into operating systems and driver development
with managed code.
Still, my guess is that a manged o/s for some real-world purpose is a
half-decade away and for general purposes it is likely to be at least twice
as far off as that.
Of course, no one important shares his long range plans with me so I could
be all wrong. ;-)
Regards,
Will | | | | re: "Poll" Has C# Generally Replaced C++
Greg wrote:[color=blue]
>
> I guess my next question is then why would Microsoft call it C# which
> is: C++
> ++ ?[/color]
Are you *really* trying to understand marketing naming woodoo from a
pragmatic ant technical point of view ;-)
Arnaud
MVP - VC | | | | re: "Poll" Has C# Generally Replaced C++
For .NET 2.0, C++/CLI lets you do everything C# can + a lot more - so it's
definitely your better option.
For Longhorn, I am not so sure. There's no direct XAML support for C++. So
you are going to have to hand-code your UIs (and unless all your apps have
simple dialogs with 1-3 controls on them, that's a pain in the neck). Of
course, maybe they are working on XAML support for C++ too, and if so,
there's no reason to use C# :-)
--
Regards,
Nish [VC++ MVP]
"Greg" <gm@mcpherran.com> wrote in message
news:EE1D679B-952E-4B99-807E-C7D4A2D2E1A8@microsoft.com...[color=blue]
> 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[/color] | | | | re: "Poll" Has C# Generally Replaced C++
I think C# is a general replacement for C++ even though C++ has its place.
C was a quick "throw-together" language at Bell Labs that took hold. C++ was
built on top of C an carried the syntax.
C# has superior syntax. In C/C++ both the pointer declaration and the object
of the pointer use a * . Also C# array are declared as a type rather than
type/context:
e.g. int[] x; v.s. int x[];
C# has the advantage of practical "non-rushed" thinking in its design.
Again. I don't deny that C++ has its place and can have advantages. However,
I think C# is the "general" replacement for C++. People may not fully realize
it yet. That is my opinion. | | | | re: "Poll" Has C# Generally Replaced C++
"Greg" <gm@mcpherran.com> skrev i meddelandet
news:F475ECF5-C9CD-49C5-A8F9-9B9204A09658@microsoft.com...[color=blue]
>I think C# is a general replacement for C++ even though C++ has its
>place.
>
> C was a quick "throw-together" language at Bell Labs that took hold.
> C++ was
> built on top of C an carried the syntax.
>
> C# has superior syntax. In C/C++ both the pointer declaration and
> the object
> of the pointer use a * .[/color]
C++ also introduced the reference, to reduce the use of pointers.
I also object to the use of C/C++ to denote a single language. :-)
They are *very* different.
[color=blue]
> Also C# array are declared as a type rather than
> type/context:
>
> e.g. int[] x; v.s. int x[];[/color]
std::vector<int> x;
[color=blue]
>
> C# has the advantage of practical "non-rushed" thinking in its
> design.[/color]
I have the highest regards for Anders Hejlsberg, but believe he
designed a Java killer with the best from Delphi, not a C++
replacement. http://msdn.microsoft.com/vcsharp/ho...g/default.aspx
[color=blue]
> Again. I don't deny that C++ has its place and can have advantages.
> However,
> I think C# is the "general" replacement for C++. People may not
> fully realize
> it yet. That is my opinion.[/color]
Ok, then count me in with the "People".
Bo Persson | | | | re: "Poll" Has C# Generally Replaced C++
"Bo Persson" wrote:
[color=blue]
>
> std::vector<int> x;
>[/color]
std::vector<int> x;
vs.
int[] x;
I rest my case :-) | | | | re: "Poll" Has C# Generally Replaced C++
"Greg" <gm@mcpherran.com> wrote in message
news:94379ABE-06A0-4DB3-B29A-1B7801D290F0@microsoft.com...[color=blue]
> "Bo Persson" wrote:[color=green]
>>
>> std::vector<int> x;
>>[/color]
>
> std::vector<int> x;
>
> vs.
>
> int[] x;
>
> I rest my case :-)[/color]
std::vector<int> x;
vs.
System.Collections.Generic.List<int> x;
Better to compare apples to apples...
-cd | | | | re: "Poll" Has C# Generally Replaced C++
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam >
wrote in message news:OXq8aN1$FHA.2320@TK2MSFTNGP11.phx.gbl...
Still not apples to apples - how 'bout:
std::vector<int> x;
vs.
System.Collections.Generic.List<int> x = new
System.Collections.Generic.List<int>();
-cd | | | | re: "Poll" Has C# Generally Replaced C++
"Bo Persson" <bop@gmb.dk> wrote in message
news:%23Al9G9z$FHA.140@TK2MSFTNGP12.phx.gbl...[color=blue]
>[/color]
<SNIP>[color=blue]
> Ok, then count me in with the "People".
> Bo Persson[/color]
Count me as thinking just like Bo does.
-Michael Viking | | | | re: "Poll" Has C# Generally Replaced C++
Greg wrote:
[color=blue]
> e.g. int[] x; v.s. int x[];[/color]
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*.
[color=blue]
> C# has the advantage of practical "non-rushed" thinking in its design.[/color]
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 | | | | re: "Poll" Has C# Generally Replaced C++
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:
[color=blue]
> No destructor (!!!) means no RAII, which is big
> problem when an object holds a resource. Tom
>[/color] | | | | re: "Poll" Has C# Generally Replaced C++
JAL wrote:[color=blue]
> "Tamas Demjen" wrote:
>[color=green]
>> No destructor (!!!) means no RAII, which is big
>> problem when an object holds a resource. Tom[/color]
>
> This is as expected in a garbage collected runtime,[/color]
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.
[color=blue]
> but you can still do deterministic cleanup:
>
> http://www.geocities.com/Jeff_Louie/oop26.htm
>[/color]
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 | | | | re: "Poll" Has C# Generally Replaced C++
JAL wrote:[color=blue]
> This is as expected in a garbage collected runtime, but you can still do
> deterministic cleanup:
>
> http://www.geocities.com/Jeff_Louie/oop26.htm[/color]
I don't want that. try/catch can't do
std::vector<boost::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
deterministically, 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 | | | | re: "Poll" Has C# Generally Replaced C++
Greg wrote:[color=blue]
> 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.
>[/color]
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 | | | | re: "Poll" Has C# Generally Replaced C++
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:
[color=blue]
> "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam >
> wrote in message news:OXq8aN1$FHA.2320@TK2MSFTNGP11.phx.gbl...
>
> Still not apples to apples - how 'bout:
>
> std::vector<int> x;
>
> vs.
>
> System.Collections.Generic.List<int> x = new
> System.Collections.Generic.List<int>();
>
> -cd
>
>
>[/color] | | | | re: "Poll" Has C# Generally Replaced C++
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:
[color=blue]
>
> 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
>
>
>
>[/color] | | | | re: "Poll" Has C# Generally Replaced C++
Tom... C++/cli has implemented deterministic destructors by implementing the
semantics of a ref class "on the stack." It basically automates the using
construct. http://www.geocities.com/jeff_louie/...estructors.htm
"Tamas Demjen" wrote:[color=blue]
>And I believe C++/CLI
> is prepared to deal with those cases too. C# is not. Correct me if I'm
> wrong.[/color] | | | | re: "Poll" Has C# Generally Replaced C++
I don't really understand your point. Java and C# are garbage collected and
objects are created using reference semantics.They do not normally use
reference counting so finalization is not deterministic. Seems to me there is
a direct link between the decision to use garbage collection and the lack of
deterministic finalization.
C# value types do not have destructors, but C++/cli ref classes can be
declare "on the stack" so that the "destructor" gets called when the "value"
goes out of scope, much in the way that delete is called on a contained
pointer when the smart pointer goes out of scope.
"Carl Daniel [VC++ MVP]" wrote:
[color=blue]
> 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.[/color] | | | | re: "Poll" Has C# Generally Replaced C++
No... but smart pointers replace the try catch also
void foo()
{
auto_ptr<MyClass> p(new MyClass);
p->DoSomething();
}
replaces
void foo()
{
MyClass* p;
try {
p = new MyClass;
p->DoSomething();
delete p;
}
catch (...) {
delete p;
throw;
}
}
"Tamas Demjen" wrote:
I don't want that. try/catch can't do
std::vector<boost::shared_ptr<Resource> > items; | | | | re: "Poll" Has C# Generally Replaced C++
JAL wrote:[color=blue]
> I don't really understand your point. Java and C# are garbage collected and
> objects are created using reference semantics.They do not normally use
> reference counting so finalization is not deterministic. Seems to me there is
> a direct link between the decision to use garbage collection and the lack of
> deterministic finalization.[/color]
Regarding memory this is true. But regarding resources (e.g. file
handles) you cannot always rely on garbage collection.
You have to write:
void foo()
{
using ( File f1 = new File(), File f2 = new File())
{
....
} <-- Here the files are automatically closed
}
Would be fairly easy to allow using keyword to be used in a more direct
manner in C#:
void foo()
{
using File f1; // Automatically default constructed
using File f2("aa"); // Automatically constructed
} <-- Here the files would be automatically closed
But this unfortunately doesn't help if you need to have an object in
multiple lists and automatically disposed after the last reference has
been removed from the list.
[color=blue]
> [...][/color]
Andre | | | | re: "Poll" Has C# Generally Replaced C++
Greg wrote:[color=blue]
> int[] x;
>
> x has all the methods of ICollection and Array. So I think int[] x is apples
> to apples.[/color]
An array in C# is not extensible. A std::vector is....
Arnaud
MVP - VC | | | | re: "Poll" Has C# Generally Replaced C++
JAL wrote:[color=blue]
> I don't really understand your point. Java and C# are garbage
> collected and objects are created using reference semantics.They do
> not normally use reference counting so finalization is not
> deterministic. Seems to me there is a direct link between the
> decision to use garbage collection and the lack of deterministic
> finalization.[/color]
Deterministic object lifetime and deterministics memory reclamation are two
separate things. C# joins them into a single concept, but they needn't be
so joined. C++/CLI is an example of a language that treats them as the
separate things that they are.
-cd | | | | re: "Poll" Has C# Generally Replaced C++
"JAL" <JAL@discussions.microsoft.com> skrev i meddelandet
news:DBBC2C1F-D31E-4032-8C66-236A2AFB2F32@microsoft.com...[color=blue]
> No... but smart pointers replace the try catch also
>
> void foo()
> {
> auto_ptr<MyClass> p(new MyClass);
> p->DoSomething();
> }
>
> replaces
>
> void foo()
> {
> MyClass* p;
> try {
> p = new MyClass;
> p->DoSomething();
> delete p;
> }
> catch (...) {
> delete p;
> throw;
> }
> }[/color]
Or, if you are using proper C++:
void foo()
{
MyClass m;
m.DoSomething();
}
No problem! ;-)
Bo Persson | | | | re: "Poll" Has C# Generally Replaced C++
JAL wrote:[color=blue]
> No... but smart pointers replace the try catch also[/color]
My point is that the C# using keyword works for trivial cases when you
locally allocate and object and delete it right away. But C# using
doesn't work when the object has a longer life span, but still requires
automatic destruction. How do you store a list of resources in a
container/collection with deterministic cleanup?
All you're showing is that
C++ auto_ptr<T> t(new T)
is the same as
C# using(T t = new T)
That I agree with. But the real differences begin to show up when I can
do in C++ vector<shared_ptr<T> >. In C# I don't think there's a solution
to it. I actually tried to put objects into a List<T> using C# 2.0, and
it didn't automatically call Dispose on T. So List<T>::Dispose (if it
has such a thing at all) doesn't call Dispose for the contained objects.
I think it would be nice if .NET collections had a Dispose method, which
would call Dispose for its members. But even that wouldn't solve a lot
of other problems that reference counted shared_ptr does. What if a
single resource has 2 object copies, both handling the same resource,
and the actual resource should only be disposed when the last object
copy goes out of existence?
As Carl said, pure managed memory reclamation is not the same thing as
resource reclamation. In C# you don't worry about releasing allocated
managed memory, but you still have the burden of reclaiming resouces,
and the language doesn't provide a very good support for that. The using
keyword only solves that for trivial cases, when the object is create
and delete in the *same scope*, which can't always be ensured. In
complex applications resources are stored in containers, in other
objects, and they're destructed in a very complex way.
One more advantage of the boost implementation is weak_ptr. It clearly
separates ownership semantics (shared_ptr) from reference semantics
(weak_ptr). Using weak_ptr you can be sure that you don't leave trash
objects behind accidentally. It automatically makes sure that when the
last shared_ptr goes out of existence, all weak_ptr's that refer to the
object get NULLed out automatically. I challenge you to implement this
in C#, without manually having to call Dispose. I believe it's doable in
C++/CLI, even if we don't initially have such a solution yet.
I'd like to note that even in C++/CLI the standard .NET containers
suffer from deterministric destruction problems:
using namespace System::Collections::Generic;
ref class Guarded
{
public:
~Guarded() { Console::WriteLine(L"~Guarded"); }
};
int main(array<System::String ^> ^args)
{
List<Guarded^> items;
items.Add(gcnew Guarded);
return 0;
}
Although "items" uses stack semantics, when it goes out of scope it
doesn't Dispose its members. And trying to do
List<Guarded> items
doesn't work, because List<T> is a generic, not a template. I'm not sure
if the upcoming STL.NET will solve this. It's very concerning when I
program in .NET, even in C++/CLI. I simply can't use the .NET containers
to store objects that wrap unmanaged types, because the Dispose pattern
is broken. I think it's just a matter of time before really good C++/CLI
container implementations come out, where we'll be able to write
vector<shared_ptr<ManagedClass> >
Not having the proper tools for this problem, I feel like I live in
danger, just like C programmers do (whether they admit it or not). Or
even more so, because C programmers are not used to exceptions, but .NET
programmers must think of exception safety. Every system that provides
exceptions but no exception safety is a disaster waiting to happen.
Tom | | | | re: "Poll" Has C# Generally Replaced C++
Some have pointed out advantages of C++ which I don't contest. Yet, I am not
sure these are outweighed by other considerations for many .NET development
scenarios.
There are some cases where C++ is the only option: e.g. a pure native
Windows App with no .NET Runtime required.
However for a .NET app, if C++ is on par with C#, then how does one decide
which language to use. Are there any criteria besides being already familiar
with C++ etc.?
I.e. are there any concrete reasons why the full development cycle right up
to delivery will be more cost effective and yield greater ROI using one
language vs. the other?
Thank You
--
Greg McPherran www.McPherran.com
"Andre Kaufmann" wrote:
[color=blue]
> Greg wrote:[color=green]
> > 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.
> >[/color]
>
> 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
>[/color] | | | | re: "Poll" Has C# Generally Replaced C++
Hi Tom... I agree that using comes up short when compared to smart pointers.
Using is "... about as close as we can get to a smart pointer and RAII in C#"
The best I can do in C# is:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace DeterminedCollection
{
interface IData
{
int I { get;}
}
interface IMyInterface : IData, IDisposable{}
class Dummy : IMyInterface
{
private bool disposed = false;
private int i;
public Dummy(int i)
{
this.i = i;
}
public void Dispose()
{
Dispose(true);
Console.WriteLine("disposed");
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing) // called from Dispose
{
// Dispose managed resources.
}
// Clean up unmanaged resources here.
}
disposed = true;
}
~Dummy() // maps to finalize
{
Dispose(false);
}
public int I {
get {
if (disposed) { throw new ObjectDisposedException("Dummy"); }
return i;
}
}
}
class JALCollection : IDisposable //, IEnumerator
{
private bool disposed = false;
private ArrayList list = new ArrayList();
// ASSERT d is not null
// ASSERT no object holds a reference to
// d outside of this class
// USAGE Add(new MyClass());
// where MyClass implements IMyInterface
public void Add(IMyInterface d) {
if (d != null)
{
list.Add(d);
}
else { throw new ArgumentException(); }
}
// test only, not safe! implement IEnumerator
public int GetValue(int i)
{
return ((IData)list[i]).I;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
foreach (IDisposable d in list)
{
d.Dispose();
}
}
private void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing) // called from Dispose
{
// Dispose managed resources.
}
// Clean up unmanaged resources here.
}
disposed = true;
}
~JALCollection() // maps to finalize
{
Dispose(false);
}
}
class Program
{
static void Main(string[] args)
{
using (JALCollection jal= new JALCollection())
{
jal.Add(new Dummy(1));
Console.WriteLine(jal.GetValue(0)); // test only
}
Console.ReadLine();
}
}
} | | | | re: "Poll" Has C# Generally Replaced C++
Hi Bo... Of course, the code is not _exactly_ equivalent :) Stack vs Heap
allocation.
"Bo Persson" wrote:
[color=blue]
>
> "JAL" <JAL@discussions.microsoft.com> skrev i meddelandet
> news:DBBC2C1F-D31E-4032-8C66-236A2AFB2F32@microsoft.com...[color=green]
> > No... but smart pointers replace the try catch also
> >
> > void foo()
> > {
> > auto_ptr<MyClass> p(new MyClass);
> > p->DoSomething();
> > }
> >
> > replaces
> >
> > void foo()
> > {
> > MyClass* p;
> > try {
> > p = new MyClass;
> > p->DoSomething();
> > delete p;
> > }
> > catch (...) {
> > delete p;
> > throw;
> > }
> > }[/color]
>
> Or, if you are using proper C++:
>
> void foo()
> {
> MyClass m;
> m.DoSomething();
> }
>
>
> No problem! ;-)
>
>
> Bo Persson
>
>
>
>[/color] | | | | re: "Poll" Has C# Generally Replaced C++
Greg wrote:[color=blue]
> Some have pointed out advantages of C++ which I don't contest. Yet, I am not
> sure these are outweighed by other considerations for many .NET development
> scenarios.
>
> There are some cases where C++ is the only option: e.g. a pure native
> Windows App with no .NET Runtime required.[/color]
Currently yes. But Microsoft (research) has a native C#/MSIL compiler
and there are AFAIK also some commercial native C# compilers.
Though all memory is still garbage collected and surely the C# native
compilers are somewhat restricted.
[color=blue]
> However for a .NET app, if C++ is on par with C#, then how does one decide
> which language to use. Are there any criteria besides being already familiar
> with C++ etc.?[/color]
I think you are more productive by using C#/VB.Net than C++ for a .NET
app, at least with Visual Studio.
Just because you have many more IDE features available for that
languages. Refactoring, Code Snippets, more Intellisense Features, Test
Cases and many others and they are much faster in compilation.
If you need to access unmanaged resources or (old) C++ code surely
C++/CLI is the way to go.
But since the languages in .NET can be very tightly coupled, it's no big
deal to mix them. Write a C++/CLI Dll which is accessing and dealing
with the umanaged resources and exports .NET wrapper classes and consume
the from C#/VB.Net or any other .NET language.
Another criteria is speed / optimized code. Optimized code currently can
be written only in a native language, like C++ and the C++ compiler
generates more optimized MSIL code than the C#/VB.Net compilers do
(currently).
[color=blue]
> I.e. are there any concrete reasons why the full development cycle right up
> to delivery will be more cost effective and yield greater ROI using one
> language vs. the other?
>[/color]
See above. For GUI applications or GUI components I wouldn't use C++,
but prefer C#, just for the reasons I mentioned above.
For speed centric and optimized code I would prefer C++.
[color=blue]
> Thank You[/color]
Regards,
Andre | | | | re: "Poll" Has C# Generally Replaced C++
Andre.. Ok this stuff IS harder than brain surgery. If I get some time I will
try to implement this but after doing 40 hours of neurosurgery I need to go
to sleep :).
"Andre Kaufmann" wrote:
[color=blue]
> But this unfortunately doesn't help if you need to have an object in
> multiple lists and automatically disposed after the last reference has
> been removed from the list.
>[color=green]
> > [...][/color]
>
> Andre
>[/color] | | | | re: "Poll" Has C# Generally Replaced C++
"JAL" <JAL@discussions.microsoft.com> skrev i meddelandet
news:4F6C3218-02A1-40D6-BCDA-6DF0FED97735@microsoft.com...[color=blue]
> Hi Bo... Of course, the code is not _exactly_ equivalent :) Stack vs
> Heap
> allocation.[/color]
I know it's different, that was a point. :-)
Managed code solves the memory leak "problem" of
void foo()
{
MyClass* p = new MyClass;
p->DoSomethingThatThrows();
delete p;
}
My solution is not to invent a new language, but use what is already
in C++
void foo()
{
MyClass m;
m.DoSomethingThatThrows();
}
Here the m object, and any subobjects or allocations done by m, will
be destroyed at the end of scope. The destructor of m is called,
Always.
So, there isn't any problem in the first place, and then I'm offered a
solution. No thanks. .-)
Bo Persson
[color=blue]
> "Bo Persson" wrote:
>[color=green]
>>
>> "JAL" <JAL@discussions.microsoft.com> skrev i meddelandet
>> news:DBBC2C1F-D31E-4032-8C66-236A2AFB2F32@microsoft.com...[color=darkred]
>> > No... but smart pointers replace the try catch also
>> >
>> > void foo()
>> > {
>> > auto_ptr<MyClass> p(new MyClass);
>> > p->DoSomething();
>> > }
>> >
>> > replaces
>> >
>> > void foo()
>> > {
>> > MyClass* p;
>> > try {
>> > p = new MyClass;
>> > p->DoSomething();
>> > delete p;
>> > }
>> > catch (...) {
>> > delete p;
>> > throw;
>> > }
>> > }[/color]
>>
>> Or, if you are using proper C++:
>>
>> void foo()
>> {
>> MyClass m;
>> m.DoSomething();
>> }
>>
>>
>> No problem! ;-)
>>
>>
>> Bo Persson
>>
>>
>>
>>[/color][/color] | | | | re: "Poll" Has C# Generally Replaced C++
"Greg" <gm@mcpherran.com> skrev i meddelandet
news:A3A79B86-C3DF-4FDB-8E2B-9033B9D56177@microsoft.com...[color=blue]
> Some have pointed out advantages of C++ which I don't contest. Yet,
> I am not
> sure these are outweighed by other considerations for many .NET
> development
> scenarios.
>
> There are some cases where C++ is the only option: e.g. a pure
> native
> Windows App with no .NET Runtime required.
>
> However for a .NET app, if C++ is on par with C#, then how does one
> decide
> which language to use. Are there any criteria besides being already
> familiar
> with C++ etc.?[/color]
But that weighs in heavily. If I have been writing C++ code for 15-20
years, and are happy with that, what are the productivity advantages
of moving to another language?
[color=blue]
>
> I.e. are there any concrete reasons why the full development cycle
> right up
> to delivery will be more cost effective and yield greater ROI using
> one
> language vs. the other?[/color]
Exactly my question! :-)
[color=blue][color=green]
>>
>> IMHO C++ - C++/CLI and C# can be used very effectively together and
>> both
>> languages have their pros and cons.
>>[/color][/color]
That is actually 3 languages, not 2.
C++/CLI is not even close to the language called ISO C++. It just
looks similar, just like Java does.
Bo Persson | | | | re: "Poll" Has C# Generally Replaced C++
JAL wrote:
[color=blue]
> class JALCollection : IDisposable //, IEnumerator
> {
> private bool disposed = false;
> private ArrayList list = new ArrayList();[/color]
[...][color=blue]
> public void Dispose()
> {
> Dispose(true);
> GC.SuppressFinalize(this);
> foreach (IDisposable d in list)
> {
> d.Dispose();
> }
> }[/color]
Yes, this is exactly how Delphi programmers are forced to handle
containers too. Always wrap it into a 200 line class, just to achieve
the functionality of what the framework provided collection is supposed
to do. It's rather error prone when this responsibility is left up to
the programmer. Let alone the time being spent on typing in the same
code again and again. My applications use 100s of C++ containers, some
of which are inter-references, and it would be very painful to
substitute them with ad-hoc hand-written replacement containers, just
because the language doesn't provide the concept of destructors. Having
destructors makes a lot of difference, and with large projects it saves
a whole lot of time in the long run.
To be fair, using generics in C# 2.0 you can write your own dream
resource-holding containers, that's true, so you don't have to retype
the same kind of code again and again. But it's still a bit
disappointing to me that deterministic destruction of resources is not
automatic but often requires serious effort on the programmer's side.
Isn't it ironic that in C# you're not supposed to worry about leaks
anymore, and yet in old native C++ you can achieve safe resource
handling much easier and safer?
Of course everything can be done in every language, even in assembly,
it's just a matter of how much effort it requires, how error prone it
is, and how maintainable the code is.
Tom | | | | re: "Poll" Has C# Generally Replaced C++
Bo Persson wrote:[color=blue]
> "Greg" <gm@mcpherran.com> skrev i meddelandet
> news:A3A79B86-C3DF-4FDB-8E2B-9033B9D56177@microsoft.com...
> [...][color=green]
>> IMHO C++ - C++/CLI and C# can be used very effectively together and
>> both ...[/color]
> That is actually 3 languages, not 2.
>
> C++/CLI is not even close to the language called ISO C++. It just
> looks similar, just like Java does.[/color]
C++/CLI is an extension to C++, therefore a C++/CLI compiler must be
able to compile standard C++.
So I think it's equally true to speak of 2 and/or of 3 languages. ;-)
[color=blue]
> Bo Persson[/color]
Andre | | | | re: "Poll" Has C# Generally Replaced C++
JAL wrote:[color=blue]
> Andre.. Ok this stuff IS harder than brain surgery. If I get some time I will
> try to implement this but after doing 40 hours of neurosurgery I need to go
> to sleep :).
>[/color]
Uff. I would just state the opposite. You (will) have a comparison
between both - I better don't give it a try - should be better for the
patient ;-)
[...]
Andre | | | | re: "Poll" Has C# Generally Replaced C++
"Andre Kaufmann" <andre.kaufmann.bei@t-online.de> skrev i meddelandet
news:efotRbaAGHA.2708@TK2MSFTNGP12.phx.gbl...[color=blue]
> Bo Persson wrote:[color=green]
>> "Greg" <gm@mcpherran.com> skrev i meddelandet
>> news:A3A79B86-C3DF-4FDB-8E2B-9033B9D56177@microsoft.com...
>> [...][color=darkred]
> >> IMHO C++ - C++/CLI and C# can be used very effectively together
> >> and
> >> both ...[/color]
>> That is actually 3 languages, not 2.
>>
>> C++/CLI is not even close to the language called ISO C++. It just
>> looks similar, just like Java does.[/color]
>
> C++/CLI is an extension to C++, therefore a C++/CLI compiler must be
> able to compile standard C++.[/color]
No, it does not.
There are some extensions, but also some parts that are missing, and
some parts that just behave differently.
[color=blue]
> So I think it's equally true to speak of 2 and/or of 3 languages.
> ;-)[/color]
Let's disagree. :-)
Bo Persson | | | | re: "Poll" Has C# Generally Replaced C++
Sounds like C++ meets all your requirements and you have no need to code in a
garbage collected environment.
"Bo Persson" wrote:
[color=blue]
>
> "JAL" <JAL@discussions.microsoft.com> skrev i meddelandet
> news:4F6C3218-02A1-40D6-BCDA-6DF0FED97735@microsoft.com...[color=green]
> > Hi Bo... Of course, the code is not _exactly_ equivalent :) Stack vs
> > Heap
> > allocation.[/color]
>
> I know it's different, that was a point. :-)
>
> Managed code solves the memory leak "problem" of
>
> void foo()
> {
> MyClass* p = new MyClass;
> p->DoSomethingThatThrows();
> delete p;
> }
>
> My solution is not to invent a new language, but use what is already
> in C++
>
> void foo()
> {
> MyClass m;
> m.DoSomethingThatThrows();
> }
>
> Here the m object, and any subobjects or allocations done by m, will
> be destroyed at the end of scope. The destructor of m is called,
> Always.
>
> So, there isn't any problem in the first place, and then I'm offered a
> solution. No thanks. .-)
>
>
> Bo Persson
>
>
>[color=green]
> > "Bo Persson" wrote:
> >[color=darkred]
> >>
> >> "JAL" <JAL@discussions.microsoft.com> skrev i meddelandet
> >> news:DBBC2C1F-D31E-4032-8C66-236A2AFB2F32@microsoft.com...
> >> > No... but smart pointers replace the try catch also
> >> >
> >> > void foo()
> >> > {
> >> > auto_ptr<MyClass> p(new MyClass);
> >> > p->DoSomething();
> >> > }
> >> >
> >> > replaces
> >> >
> >> > void foo()
> >> > {
> >> > MyClass* p;
> >> > try {
> >> > p = new MyClass;
> >> > p->DoSomething();
> >> > delete p;
> >> > }
> >> > catch (...) {
> >> > delete p;
> >> > throw;
> >> > }
> >> > }
> >>
> >> Or, if you are using proper C++:
> >>
> >> void foo()
> >> {
> >> MyClass m;
> >> m.DoSomething();
> >> }
> >>
> >>
> >> No problem! ;-)
> >>
> >>
> >> Bo Persson
> >>
> >>
> >>
> >>[/color][/color]
>
>
>[/color] |  | | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,272 network members.
|