C# vs C++

  • Thread starter Thread starter Metal
  • Start date Start date
M

Metal

Is C# better than C++?

What are the advantages of C++ over C# and vice versa?

Thanks and regards
Metal
 
Metal,

C# is a lot better C++.
For one, C# is part of .NET, so it has a lot of good features like
managed code.
In C++, with the use of pointers, the code can be very unsafe and it
isn't 'visual'; in other words, all the code that you need to write is
all done by YOU.
Besides, currently now and into the future people are using things like
Windows Applications, Web etc. C# makes it so much easier to devolop
those kind of applications.

However, there ARE SOME advantages of C++ over C#, I must admit.

This is an interesting topic,

Visually Seen #
 
C# ...

* is a cleaner language that is easy to program, read and maintain
* has a much higher productivity rate
* contains features that allows you to generate HTML documentation from
XML tags that describe your methods, properties, events and fields
* eliminates the need for pointers, which are essentially useless
* almost everything in c# including basic data types are derived from a
common class and therefore share common functionality
* uses a fairly consistant model for inheritance, interfaces, delegates
and events
* eliminates garbage collection and the need to manually destroy
objects
* is based on using managed code so that you are not required to
release memory on objects
* uses namespaces so that you can properly organize your classes into
logical units
*

C++...

* good for higher performance (math, graphics, etc)
* required to work with lower levels (device drivers, etc)

Most people who have developed with both languages will sooner choose
C# over C++ for most application development. C++ will not dissappear
(at least not yet) and has its place but it is an archaic language that
is complex, messy and out-of-date with the times.

Best Regards
Johann Blake
 
You really cannot use the "it's part of .NET" as an argument for C#
being better than C++. That is because C# is a language and is
independent of the platform. C# can run on other operating systems
using platforms other than .NET. While C# running on Windows developed
using Visual Studio .NET does make use of the .NET framework, these are
advantages of using the .NET framework and not the language itself.

Best Regards
Johann Blake
 
C# is a managed language - it requires an environment that has facilities like delegates, metadata extensions (attributes) and garbage collection (remember there is no delete keyword). I'm not aware of any C# implementation that is not CLR (or at least CLI) based and frankly I can't see a way of there being one.

Of course your argument holds true for reason's other than you've stated: because C++/CLI (the new managed C++ language) is part of .NET in the same way.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

You really cannot use the "it's part of .NET" as an argument for C#
being better than C++. That is because C# is a language and is
independent of the platform. C# can run on other operating systems
using platforms other than .NET. While C# running on Windows developed
using Visual Studio .NET does make use of the .NET framework, these are
advantages of using the .NET framework and not the language itself.

Best Regards
Johann Blake
 
There's no such thing as a "managed language" when talking generically
about programming languages. The word "managed" was coined by Microsoft
and has to do with the .NET Framework and not the language itself.
There's nothing preventing someone from writing a C# compiler that
generates machine code for some microcontroller where no CLR is even
required. In such a case, you can't call this "managed".

Johann Blake
 
What I'm saying is that I can't see how you'd get away without a GC being there - it, as a language, requires runtime support.

Managed has everything to do with the .NET framework. Code that runs within the confines of the .NET framework is termed managed. Yes managed was coined by Microsoft - but so was .NET.

Regards

Richard Blewett - - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

There's no such thing as a "managed language" when talking generically
about programming languages. The word "managed" was coined by Microsoft
and has to do with the .NET Framework and not the language itself.
There's nothing preventing someone from writing a C# compiler that
generates machine code for some microcontroller where no CLR is even
required. In such a case, you can't call this "managed".

Johann Blake
 
GC is only relevent in the world of Windows where keeping memory clean
and reusing previously created object instances has definite
advantages. But it is still only a "nice-to-have" feature, not a
"must-have" feature. The language can exist without it and in fact
does. My point is C# is NOT dependent on any sort of runtime support as
you imply. Only within the context of Windows programming using Visual
Studio .NET does that hold true.

Regards
Johann Blake
 
From ECMA 334 (The C# Standard) Section 10.9
"C# employs automatic memory management, which frees developers from
manually allocating and freeing the memory occupied by objects. Automatic
memory management policies are implemented by a garbage collector."

If it doesn't have a GC, it's not C#.
 
Johann,
But it is still only a "nice-to-have" feature, not a "must-have" feature.

I think for C# garbage collection is a "must-have" feature of the
environment. How would you release for reuse the memory in absence of GC?
The language does not offer a delete operator or any other mechanism...

Just my two cents.

Regards - Octavio
 
"C# is a lot better C++"

"BETTER" is a very relative term, depending on the task and requirements C#
can be better than C++ or C++ can be better than C#.

One of the main differences between C# and C++ is that C# has the concept of
managed code. In C# the programmer does not have to concern himself about
allocating and releasing memory, this is all done by the .Net CLR and garbage
collection. Basically in C# when an object goes out of scope, i.e. it is no
longer referenced by any other object, it has the possibility of being
cleaned up automatically, but this mechanism is non-deterministic. An object
will only be cleaned up when the Garbage Collector runs (you can call
GC.Collect(), but this is not recommended, the GC algorithms are coded to be
optimal and will do a better job than you calling it manually).

It is possible to use pointers in C#, but then you must put the code inside
an unsafe block which may not allow it to be run in some environments where
security restrictions are high and unsafe code is not permitted to run. Also
as with C++ if you use pointers and allocate memory dynamically then you run
the risk of memory leaks if you foget to deallocate the momory after use.

The possibility of not having memory leaks is a big plus for C#.

C# is also designed to be a secure language, it is not possible to have a
buffer overflow exception in C#, which is easily done in C++, which is the
cause of a lot of security bugs and viruses. the worst you should get in C#
is an exception being thrown.

Also C# is compiled into an intermediate language called IL, just like Java
is compiled into JavaBytes. because it is not compiled to any specific
hardware you can write a CLR for each type of hardware or OS and run the same
code without modification. As well as being a plus this can be seen as a
negative because there is more overhead in translating the IL language to
machine at runtime than natively running the machine code. I believe it is
possible to compile C# to a native platform but I do not have any experience
of C# native vs C++ performance so I cannot comment on this.

The list of comparisons can go on and on, here are just some of the points.

Mark R Dawson.
 
Metal said:
Is C# better than C++?

What are the advantages of C++ over C# and vice versa?

Thanks and regards
Metal
Note, I have 20+ years of experience in C, 10+ years in C++ and about
1.5 years of C#.
Better for what?? I work on a large medical imaging and reporting
system. C/C++ is the best choice for our imaging system, due to the
requirement to interface with some third party code. Also, imaging
processing seems to be faster in unmanaged C++. Now the
reporting/graphing system is in C#. Very easy to program/develop. I
believe you can develop/implement and test up to 5 times faster in C#
over c++. One task which would have taken me 2 weeks in C++ was done in
about 3 days in C#.
 
I respectfully submit that no language is "better" than another in some kind
of simplistic, definitive way. Nor is there a bullet-pointed list of
immutable "advantages" of one language over another. No one can possibly
give you an intelligent answer to "is language A better than language B"
unless they know what tasks you want to apply those languages to, and what
your personal requirements and preferences are.

Languages are tools. Each one has what are generally regarded as strengths,
but their greatest strength is also their greatest weakness. For example
from the 10,000-foot level, C#'s basic strength is that it's an excellent
general purpose language for developing line-of-business applications.
That's also its basic weakness -- if you're writing, say, a real-time device
driver.

So, as with most things in the real world, the answer is, "it depends" --
and even then, you may well disagree with my criteria for evaluating the
languages in question.

Lastly, I'd like to suggest that you may not necessarily be well-advised to
be evaluating languages. Platforms, by which I mean framework libraries,
are probably more important, and these days do not necessarily correspond
one-to-one with languages. For example, any of the thirty-some languages
currently hosted by the .NET runtime (only three of which are sold by
Microsoft as part of the .NET SDK) are more or less equivalant and
applications coded in any of them will tend to look very similar because
they all talk to the same API. Some, like VB, have backward compatibility
baggage where you have the option, to an extent, to structure your syntax
against a legacy API in addition to .NET, but that is only a consideration
if you are porting legacy code or a parochial viewpoint where you want to Do
Things The Way They've Always Been Done.

So for me, the question is, how does the .NET platform (regardless of
language) compare with other platforms such as J2EE (which happens to be wed
to just one language, Java).

--Bob
 
microsoft is dumping support for C++ next year. that does give you a hint
about what is better. go figure.

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
 
Really? It would seem strange to dump a language 6 months after giving a major refit in C++/CLI. What leads you to that conclusion? Regards Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk microsoft is dumping support for C++ next year. that does give you a hint
about what is better. go figure.

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
-------------------------------------------------------------------------------


Metal said:
Is C# better than C++?

What are the advantages of C++ over C# and vice versa?

Thanks and regards
Metal



[microsoft.public.dotnet.languages.csharp]
 
Did you know that C# was derived from 'D' which has similar Object
Orienting Programming concept. I suspect Microsoft simply rebranded 'D'
to C# for marketing reason...very smart move.

It true that C# is easier because you do not have to deal the pointer
which bring in memory leakage issue (due to type or array
incompactibility).

C# work heavily with .net framework and are closely interlinked,
designed to ensure all objects is managed safety. This bring
significant stability and operation. I just often wish there is more
tools and choice available for the window forms...which seem outdated
(for VS 2003).

While the library is extensive...it easier to work with internet,
ethernet, USB and so on. *but* you have to be aware of behaviour of
ther serial data transfer, because once eithernet is converted into
serial (RS232) at the other end....the data is no longer secured and
prone to bits flips after certains time.

However C++ still play important role for embedded computing and
smaller self contained computer.

In conclusion...I support C# programming environment because it less of
the headache and easier to work with them, it easier to read than
VS.net Basic version. I hope to move on into DirectX 3D drawing using
C#...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

C 18
C# vs. ASP.NET for web services? 2
Will a c# program run on any PC? 6
Why C# 31
C# classes 1
C# to VB.NET translator 6
C# to Oracle mapping 1
C# 4.0? 5

Back
Top