Newbie C++/C# question

Beev

Diamond Member
Apr 20, 2006
7,775
0
0
I'm wanting to get into leisure programming with it potentially becoming a career at some point if I like it and stick with it. Back when I was in high school and was interested in programming I saw stuff regarding C++ pretty much exclusively. I only recently learned about C#'s existence and was curious as to which is "better." I know most modern games are written in C++ (or so I'm told). Why don't companies use C# if it is newer/better? Should I just learn C# and apply that knowledge to C++ or vice versa?
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
They are totally different beasts. In short, C# is a managed language that requires a runtime to be installed where C++ just needs libraries and executes native code.

I wouldn't worry about 'learning' the languages so much as learning the concepts behind what you're writing, if you understand the logic and process of writing of code it shouldn't matter what language you are writing in.

That said, you most definitely should focus on one or two languages while you are learning the ropes of programming and either C++ or C# would be just fine.

I learned to code in C/C++ back in high school, but this semester is the first time I've touched C in college. It was mostly Java, Haskell, and multitudes of Lisp variants up until now. Even my programming languages class was taught with Java while using javacc.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
C# is only for managed code and requires the .NET runtime, while C/C++ can compile to native code and be used for almost any operating system not just Windows (or linux + Mono).

C# is used more for corporate development, for both desktop and server code.

C# is used for end-user applications too, but more for ones that don't require high performance (Quicken rather than MS Office). There is Microsoft's XNA library for hobby game development on PCs, 360s and Phone 7 that uses C#, but if you take a look at the titles you won't see something like Fallout or Crackdown.
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
The fact of the matter is if you "know" one, it won't require too much effort to learn the other. C# might be easier to learn the programming concepts (less time wrestling with pointers), and then learn the specifics of C++ afterwards. I personally found that working with C# and it's reference variables really gave me a better understanding of pointers in C++.

Likewise if you know C# you'll know Java. When I say "know" I'm referring to syntax, there's always each languages standard libraries you'll want to obtain familiarity with as well.
 

Beev

Diamond Member
Apr 20, 2006
7,775
0
0
Thanks guys, very helpful. I've been debating learning Java first, but I might go with C++. Which would be best to learn first (pretty much exclusively online)? If I just need to learn the concepts more than the language itself then it shouldn't matter which I do first I guess...
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
Thanks guys, very helpful. I've been debating learning Java first, but I might go with C++. Which would be best to learn first (pretty much exclusively online)? If I just need to learn the concepts more than the language itself then it shouldn't matter which I do first I guess...

If you want to focus on concepts I'd recommended Java or c# first. It all depends on if you learn better top-down or bottom-up though.
 

Beev

Diamond Member
Apr 20, 2006
7,775
0
0
If you want to focus on concepts I'd recommended Java or c# first. It all depends on if you learn better top-down or bottom-up though.

In the end I would primarily use C++ it sounds like, so C# might be best. Though if I learn Java I can probably do more with that knowledge (phone apps, etc).
 

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
C# is written in C++. Therefore, what you have available in C# won't be more than what you have available in C++. Same with Java. They introduce nothing over C++... What these languages do is provide a wrapper around what you have in C++ to keep some of the more mundane things out of the picture and are handled more behind the scenes or automatically. They give you a bit cleaner atmosphere to code in. It hides things from the developer. However easier isn't necessarily more powerful or better. I can take anything written in C# or Java and create a C++ program to do the same thing, even if it takes longer.

However, the flip side:

DirectX SDK is only available for C++. Same with Physics libraries, and all that stuff. So while it's possible to write games in C#, its likely if you do decide to write games, you will find it almost harder to do these things in C#/Java than it is to just use native C++.

In the end, depending on your choice, you will find complications going one way or another. Some things are just better suited for a particular task. If you want to write business software, database, GUI screens, etc, then stick with something like a Java or C#, if you want to write games, stick with C++.

If you just want to learn, I'd actually recommend C++ even if its harder and more complicated to get going. Once you understand things there, you will understand what C# is doing when its garbage collecting, and things like that. Because you had to do those things manually in C++, even possibly writing your own garbage collecting scheme. So you will understand the issues and why these things are there.
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
C# and the various other higher level languages aren't actually about being more powerful/better - in most cases, they're a little bit weaker. They don't exist for performance critical apps - they exist because CPU power and memory is cheap, programmers are not, and thus higher programmer productivity beats out higher performing apps in many, if not most, cases.

If you're going to want to write games....well, what kind of games? Writing Doom 5 will require C++ or the like. Writing FarmTown 2 will not.
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
C# is written in C++. Therefore, what you have available in C# won't be more than what you have available in C++. Same with Java. They introduce nothing over C++... What these languages do is provide a wrapper around what you have in C++ to keep some of the more mundane things out of the picture and are handled more behind the scenes or automatically. They give you a bit cleaner atmosphere to code in. It hides things from the developer. However easier isn't necessarily more powerful or better. I can take anything written in C# or Java and create a C++ program to do the same thing, even if it takes longer.

However, the flip side:

DirectX SDK is only available for C++. Same with Physics libraries, and all that stuff. So while it's possible to write games in C#, its likely if you do decide to write games, you will find it almost harder to do these things in C#/Java than it is to just use native C++.

In the end, depending on your choice, you will find complications going one way or another. Some things are just better suited for a particular task. If you want to write business software, database, GUI screens, etc, then stick with something like a Java or C#, if you want to write games, stick with C++.

If you just want to learn, I'd actually recommend C++ even if its harder and more complicated to get going. Once you understand things there, you will understand what C# is doing when its garbage collecting, and things like that. Because you had to do those things manually in C++, even possibly writing your own garbage collecting scheme. So you will understand the issues and why these things are there.

About the only limitations of C# would be hardware interfacing. OpenGL is a graphics library, however there are numerous C# wrappers that allow you to use these things in C# code. You also failed to mention the XNA library which is a very powerful managed graphics library that is deployed on PC, Xbox, Zune, Windows Phone, etc. In the end you simply are trading processor cycles and memory cells for more rapid development. You don't have to chase down memory leaks (as often...), segfaults, buffer overflow exploits, etc, however you get this at a cost of performance.

There isn't one better than the other for learning programming for everyone. If he gets bogged down with pointers and c-strings as opposed to learning actual programming concepts he could get discouraged and give up (which is easy to do when you learn on your own).

Also I'm not saying the OP shouldn't learn C/C++, it's just I feel given his situation, a managed language might be more accessible.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
I would start with C#. Its easier to learn and more forgiving. You can learn the principles of programming with C# and then if you feel the need for C++, I'd learn it second.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
C# is written in C++. Therefore, what you have available in C# won't be more than what you have available in C++. Same with Java. They introduce nothing over C++... What these languages do is provide a wrapper around what you have in C++ to keep some of the more mundane things out of the picture and are handled more behind the scenes or automatically. They give you a bit cleaner atmosphere to code in. It hides things from the developer. However easier isn't necessarily more powerful or better. I can take anything written in C# or Java and create a C++ program to do the same thing, even if it takes longer.

Saying C# is just a C++ wrapper is like saying that C++ is really just an assembly wrapper.

C# is its own language, unique from both Java and C++. The methods of implementing the language is similar, but that doesn't make it any less of a language. It is completely possible for the .Net framework be converted to native C# code and recompiled into its own self compiling language (Though, that would be too much work and would end up in a pretty slow framework)

To the OP. Learn either. Switching languages is easy, the hard part is learning the concepts behind the languages.
 

Kirby

Lifer
Apr 10, 2006
12,028
2
0
What kind of programming do you want to do? Each language has it's advantages for different applications. After that, it comes to preference. I learned C++ first, so I feel most comfortable with it. I also use linux a lot, so cross platform is important at times.

But if I'm doing something that requires a GUI in just Windows, I'll use C#.

Learning wise, I don't feel like I was at a disadvantage for learning C++ over some other the newer McLanguages. Some people get bogged down in the syntax, but I never really had a problem with it.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Saying C# is just a C++ wrapper is like saying that C++ is really just an assembly wrapper.

"The C Programming Language — A language which combines the flexibility of assembly language with the power of assembly language."
 

Beev

Diamond Member
Apr 20, 2006
7,775
0
0
Thanks very much for all the information, guys. Here's what one of my friends had to say:

Think about anything you use, (PS3, computer, brita filter) if you know more about it and how it works you will understand issues with it and maybe know how to fix certain things. So the question really is, do you need to know C++. I say no, but if you wanted to better understand garbage collection in C++ or pointers, then you should learn C++

C++ has it's benefits, but I'm of the mind that you should focus on the critical path and any extra information you learn along the way is bonus.

That, coupled with the information from this thread, makes me think I should go with C# first.
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
That, coupled with the information from this thread, makes me think I should go with C# first.

If you do, I highly recommend this book. It may look stupid but I think it's one of the best introductory books to programming (the head-first series is a great introduction to any topic they have a book for IMO).
 

alkemyst

No Lifer
Feb 13, 2001
83,769
19
81
If you want to focus on concepts I'd recommended Java or c# first. It all depends on if you learn better top-down or bottom-up though.

QFT...if starting today focus on JAVA or C#.

If you are looking at Microsoft shops, stick to C#. Outside that, JAVA.

It's like back in the original ASP/PHP days.

As you grow you can then spend time working back down the hole, C, C++, LISP/Scheme, VB/VBScript, etc.

All that said I found if you know the logic, the syntax is the easiest part.
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
All that said I found if you know the logic, the syntax is the easiest part.

It's because of how you learn things. For example when you first learn programming you think in the syntax and not in the logic, because you don't quite grasp the concepts being abstracted. I remember looking at a C# program and would wonder how anyone could make sense of it. That's because I would see a line like "protected List<int> name = new List<int>();", and I would think about it like a series of tokens. Once you learn you think of it at a higher level, like object declaration, assignment/creation.

Essentially once you know these processes, its much easier for your brain to tie them to a specific syntax as opposed to trying to regurgitate a random string of tokens you don't completely understand.
 

Beev

Diamond Member
Apr 20, 2006
7,775
0
0
If you do, I highly recommend this book. It may look stupid but I think it's one of the best introductory books to programming (the head-first series is a great introduction to any topic they have a book for IMO).

I went by Barnes and Noble yesterday and found that book. I really like the way it is laid out, and it seems like it tries not to be too technical. I will probably pick it up. Thanks for the suggestion.
 

CurseTheSky

Diamond Member
Oct 21, 2006
5,401
2
0
The Head First books are pretty good. They're written in a semi-funny way too, so as long as you aren't sitting there saying "this is lame, they're trying too hard to be cool," the occasional humor can really break up the mundane task of learning a language.
 

dealmaster00

Golden Member
Apr 16, 2007
1,620
0
0
If you do, I highly recommend this book. It may look stupid but I think it's one of the best introductory books to programming (the head-first series is a great introduction to any topic they have a book for IMO).

Agreed. The Head First series are great self-teaching tools for learning a programming language. I can personally vouch for Head First Java. I read this book back in high school when I was first learning to program and it helped a ton with the big concepts of the Java language and object oriented programming. I'm sure the C# edition will be similar (I happened to talk to one of the creators of the C# language today and he personally said C# was designed with Java in mind) and probably a great read for someone like yourself OP. I would also suggest starting with C# then learn C/C++ afterwards. I started with Java and it made learning C a piece of cake.
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
The Head First books are pretty good. They're written in a semi-funny way too, so as long as you aren't sitting there saying "this is lame, they're trying too hard to be cool," the occasional humor can really break up the mundane task of learning a language.

They go over their strategy in the front of the books. The style isn't about "trying to be cool", so much as it is a result of studies that show the brain remembers novelty well. Hence they try to present things in a way the brain will naturally stick to. Also they repeat things over and over again (no so close that it's annoying imo), because repetition is the way the brain learns.

I do agree that there are some people who get too stuck on the style for it to be effective with them.