Link to home
Start Free TrialLog in
Avatar of kennon2000
kennon2000

asked on

To begin, C# or C++?

Hi Experts,

I want to learn C++ or C#.  What should I choose?
I like .Net Framework, but will C++ developer eventually turn to C# if C# really portable and effective?  I am afraid I cannot edit old C++ program, is there any method to translate C++ to C#?

Thanks a lot for help!  
Avatar of CJ_S
CJ_S
Flag of Netherlands image

C++ and C# are two different languages although they do have things in common and it is possible to use unsafe code in C# (meaning C++). C# requires a totally new way of thinking, and will become a great language in the future. The advantage of a new programming language like C# is that you can work with it from the start and get the whole thing into your mind. While C++ has a very long history AND has already been proven.

We cannot decide for you, we can only help you make a decision.

C++ to C# is possible (as explained) by using unsafe code, but it won't give you the advantages of the .Net platform (like garbage collection).
Normal (C++)
public void MyFunc(int *iRes)
{
   *iRes = 10;
}

Unsafe example (C#):
unsafe public void MyFunc(int *iRes)
{
   *iRes = 10;
}

As you can see it is very similar. The * is the pointer which is NOT present in C# itself (instead you use the in, out and ref keywords). The difference between the languages is huge, but they are similar.

My personal favor is C# at the moment, also because of the unsafe functionality.

Decide for yourself

CJ

Pure C# example:

public void MyFunc(ref iRes)
{
   iRes = 10;
}

(note the difference)

CJ
Avatar of kennon2000
kennon2000

ASKER

I know more about C# than C++.  It seem MFC and ATL used in C++ need much more time to learn.  .Net Framework seem much more structuralized and well managed.  Am I right?
The greatest concern is that most company still keep their 10-year-old C++ programs, if I only know C#, I have no way to amend these program.
Thanks to CJ.  I want to know does the unsafe function of C# means its compiler accept C++ program?  If not, how is the compatibility?
If you really want to use .NET, then C# is probably useful as its libraries are tailored to that framework.  However, there are a few important things that detract from C#:

1 - There's  far more C and C++ code out there.
2 - .NET is a limited framework (granted it's big, but limited).  For general work, C# may not be as useful as C++.
3 - C# doesn't have the maturity of C++.  C++ has had time to build a really good set of libraries and features.  C# currently has what Microsoft thinks is a good set of libraries.
4 - C# is not a major evolutionary step in programming languages.  It definitely belongs to the same era as Java and other C++ work alikes.  You're not going to have programs that are easier to write with less bugs.  You might want to look at some newer types of languages, such as high-level languages (Python, Perl, etc.) or functional languages (Lisp, O'Caml, etc).  Ask yourself if you really want another C++ derivative or something new.

Personally, I have no use for .NET, and there's nothing else in C# that's caught my attention, so my vote is on C++.
ASKER CERTIFIED SOLUTION
Avatar of CJ_S
CJ_S
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> This IL is compiled whenever the program is started or when that
part of code is needed

called JITting (Just In Time)
Thanks for CJ and other experts.  You really given me good comment.
I was impressed by CJ's comment: So you can say "No i want to keep up with nowadays proven technologies
like C++" or you can say "hey I want to be a guru on this new language".
That reminded me any new technique must has the risk of being not popular and one should have the brave to try.
I have actually started learning C# a few days before.  It seem that C# like Java more than C/C++(although I know little about C/C++), especially the reference type, string and garbage collector..etc.  If I have time, I will have a look at C++ while keeping C# as the main target.
Thanks.
:-) Glad to help!