Solved

To begin, C# or C++?

Posted on 2002-03-23
8
210 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
Comment Utility
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
Comment Utility
Pure C# example:

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

(note the difference)

CJ
0
 

Author Comment

by:kennon2000
Comment Utility
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
 
LVL 4

Expert Comment

by:ct.smith
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Accepted Solution

by:
CJ_S earned 150 total points
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
:-) Glad to help!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now