Solved

To begin, C# or C++?

Posted on 2002-03-23
8
243 Views
Last Modified: 2010-04-17
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!  
0
Comment
Question by:kennon2000
  • 5
  • 2
8 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 6890778
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

0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6890782
Pure C# example:

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

(note the difference)

CJ
0
 

Author Comment

by:kennon2000
ID: 6891104
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?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:ct.smith
ID: 6891764
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++.
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 150 total points
ID: 6892320
kennon2000,
MFC and ATL are relatively easy to learn, but of course that depends on how the learner can get a grasp on it. For me it took me about a year (I was 14 when I started with MFC).

Sure C/C++ applications have been around for a VERY long time, and yes it will stay alive for a very long time, and also yes for that companies won't give up their applications right away. And why should they? C# is a totally new language. 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". I cannot tell you why you should pick any of the languages, it will be YOUR choice. I think that in the future there will be a lot of C# jobs, but don't pin me on that :-)

>> 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.
The difference is as big as between VB and C++, except that C# can use C++ code. So the above line doesn't really matter IMHO.

>> want to know does the unsafe function of C# means its
>> compiler accept C++ program? If not, how is the
>> compatibility?
I'm not quite sure what you mean. the unsafe keyword ensures that C++ is being used. So you can use pointers, references and all the other stuff that you would've used when writing C++. The compiler accepts C++ code, not a C++ program. There's also another thing you should know. In languages like VB and C++ you are used to the compiler. The code you write is being converted to native WIN32 code (assuming windows platform). With C# (and other languages  built on top of the .Net platform) the code is being converted to IL-code (Intermediate language). This IL is compiled whenever the program is started or when that part of code is needed. So compiling is like: code -> IL -> native (in memory until program ends or garbage collector runs). It is possible to compile to native code directly too (thought I'd mention that :-)...). However, I am not quite sure whether unsafe code actually compiles to IL or native code... I suppose it is IL but I am not sure.

Last thing I'd like to mention. You seem to not want C# but C++. If you still feel like that then go for that language. Choose the language that you fit in :-)

CJ


0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6892323
>> This IL is compiled whenever the program is started or when that
part of code is needed

called JITting (Just In Time)
0
 

Author Comment

by:kennon2000
ID: 6893086
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.
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6893405
:-) Glad to help!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question