C++ vs C#

  • Thread starter Thread starter TStoltz
  • Start date Start date
T

TStoltz

Hi,

I'm sorry if this question comes inapropriate but hope you can help me
answer the following:

What is the difference between C++ and C#. Can I use C++ code within the C#
code. I've heard postive things about Framework which should be similar to
MDSN - or what is it better/worse?

Please tell me why I should go for C-sharp instead of C++

Thx
 
TStoltz said:
Hi,

I'm sorry if this question comes inapropriate but hope you can help me
answer the following:

What is the difference between C++ and C#.

C# is a member of the C family of languages, much like Java. In fact it
shares many similarities with Java since both target a managed environment.
C# could be seen as a "simple" C++, without macros, templates, and multiple
inheritance. It adds first class support for properties and events, and
replaces function pointers with delegates, which are effectively type-safe
function pointers. C# 2.0 has generics which are similar in some respects to
C++ templates. C# also does not support deterministic finalization, since it
relies on the .NET garbage collector to handle memory.
Can I use C++ code within the C# code.

Not directly no. C# can call into other .NET assemblies, including ones
developed with Managed C++, or C++/CLI (both are basically C++ flavours
targetting .NET). Via COM Interop C# can call C++ code which was compiled
into a COM DLL, and via PInvoke C# can call C++ code compiled into a Windows
DLL.

Managed C++ and C++/CLI offer an additional interoperation capability called
IJW, which allows you to use unmanaged C++ code in your managed C++ DLLs.
Needless to say this is very useful if you have a lot of C++ code you need
to work with.
I've heard postive things about Framework which should be similar to MDSN -
or what is it better/worse?

Do you mean MSDN? If so, this is just the Microsoft developer documentation.
The Framework is the actual .NET system.
Please tell me why I should go for C-sharp instead of C++

There's no hard and fast rule here. Basically if you've decided to target
the .NET Framework, and you're not doing too much communication with C++
code, then C# will generally get your code out the door quicker and with
less bugs. This is a function of both the cleaned up syntax and the memory
management features of the .NET framework (which are also available with
Managed C++ and C++/CLI).

I much prefer C#, since I find it has a much cleaner syntax than C++ and
less ambiguities. Switching from C++ to C# led to a 50%+ developer
productivity boost on one of the projects I was involved in. That said, C#
is not a panacea for all ills, and sometimes you are better off with C++,
but these situations are few and far between in my experience.
 
x-no-archive: yes

C++ is a pedal to the metal nitty gritty very high performance object
oriented programming language with wide support, an excellent STL (Standard
Template Library) and many other libraries and lots of books written for it.
It is a very complicated language however and you'd better get real used to
pointers, references, and pointers to pointers, and pointers to references
of pointers to objects containing arrays of pointers if you want to use it.

If you use C++ to program for Windows you will have to learn five thousand,
four hundred and fifty-two (5,452) different macro names for strings and no
two are really compatible with only 314 different versions of every function
needed for each one: LPSTR LPCSTR LPPCSTSTRST WCTSTR WPCSTR STRWPPCSTR STR
cstr cstring CString WCString WCpyString <string> wstr strcpyw strcpyl
lstrcpy cpycpystyr STSTRSS CSTRWP LPSTRCPY LWPSTR CSTRWPLSTR ... etc.

C# is a high performance (managed) interpreted object oriented language.
Lots of books, expanding libraries, lots of support and an excellent .NET
framework. It has simplified programming for Windows and seems to be the
future of programming for Windows. Yes, engines for the language are being
developed for other than Windows platforms. It stays relatively
uncomplicated until you get into interfaces, delegates and attributes etc.
In C#, strings actually seem to make real sense.

You can mix C++ and C# languages but there are considerations when you do
so.
 
C# is a high performance (managed) interpreted object oriented language.

C# isn't interpreted - it's JIT compiled. There's a big difference.

(I broadly agree with the rest of your post.)
 
x-no-archive: yes

C++ is a pedal to the metal nitty gritty very high performance object
oriented programming language with wide support, an excellent STL (Standard
Template Library) and many other libraries and lots of books written for it.
It is a very complicated language however and you'd better get real used to
pointers, references, and pointers to pointers, and pointers to references
of pointers to objects containing arrays of pointers if you want to use it.

If you use C++ to program for Windows you will have to learn five thousand,
four hundred and fifty-two (5,452) different macro names for strings and no
two are really compatible with only 314 different versions of every function
needed for each one: LPSTR LPCSTR LPPCSTSTRST WCTSTR WPCSTR STRWPPCSTR STR
cstr cstring CString WCString WCpyString <string> wstr strcpyw strcpyl
lstrcpy cpycpystyr STSTRSS CSTRWP LPSTRCPY LWPSTR CSTRWPLSTR ... etc.

C# is a high performance (managed) interpreted object oriented language.
Lots of books, expanding libraries, lots of support and an excellent .NET
framework. It has simplified programming for Windows and seems to be the
future of programming for Windows. Yes, engines for the language are being
developed for other than Windows platforms. It stays relatively
uncomplicated until you get into interfaces, delegates and attributes etc.
In C#, strings actually seem to make real sense.

You can mix C++ and C# languages but there are considerations when you do
so.

You should not if you have competence in c++. If you dont or worse
have been VB programmer by all means use c#. It gives you access to a
broad framework, although no low level access like c++. Also it is
more forgiving like java with regard to complexity and memory
management.
If for instance you want to write essentially two tier applications(
database with some gui) then by all means use c#, java, delphi, vb.net
or whatever low level encapulating language).
If on the other hand you think complexity is your job stay with c++.

Hope it helps,



Rick
 
Rick Elbers said:
You should not if you have competence in c++. If you dont or worse
have been VB programmer by all means use c#. It gives you access to a
broad framework, although no low level access like c++. Also it is
more forgiving like java with regard to complexity and memory
management.
If for instance you want to write essentially two tier applications(
database with some gui) then by all means use c#, java, delphi, vb.net
or whatever low level encapulating language).
If on the other hand you think complexity is your job stay with c++.

That depends on what you mean by complexity. It's perfectly possible to
write complex apps in C# - the difference is that the code itself
doesn't tend to look as complex as it does in C++.

I see nothing wrong with C++ programmers taking up C# as a "cleaner"
language than C++. Yes, C++ has added complexity within the language
itself, but many people think that's more of a bad thing than a good
thing. As I say, you don't need a complex language to create complex
apps.

Of course, there are things you *do* need C/C++ (or another low level
and unmanaged language for), but it's more a case of level of interface
with the hardware and OS which is important than the complexity of the
app in question.
 
Back
Top