views:

1460

answers:

16

With languages like C# that can basically do anything, I found a drawback that could not be the case in the future, and that is the lack of many open source 3rd party libraries that are well documented to choose from. However with C++, there are many libraries to choose from, and this is a big pro for me. One thing I want to get into is game programming, but XNA is too tied into Windows and Microsoft. OGRE looks fantastic to me, but it's a C++ library.

I have a basic knowledge of C++, but I don't know how to use pointers or know much about the STL. I do know that C++ does not hold your hand like C# does, but I'm willing to invest time in learning if it's worth it.

+8  A: 

Figure out what you need to do, then learn the language you need to do it.

Lance Roberts
...hmm you sound like shrink
Andreas Grech
:) - I've just found that learning a language just to learn it isn't near as useful as when you have a good use for it.
Lance Roberts
It's true, though. There's a reason shrinks say it. If C# suits what you're doing use C#. I'm in love with C++, but if I need to make a simple GUI application, why waste time getting everything up and running in C++ while in the same time I could be done in C#. Likewise, if I need a performance application, I find C++ lets me express how I want to do that, and it's quick.
GMan
C++ is tedious to learn, but has a great open source community following behind it making tons of libraries like OGRE available to use, but if this won't be the case with C# for many years then it will be worth learning C++ to me. I'd hate to spend many hours learning C++ only to find C# to be on par in the next year.
M4dRefluX
+45  A: 

C++ is a great language to learn, if you have the time I would advise learning it for these reasons:

It is still widely used.

C++ is the predominant language used for programming all computer and console games. Systems programmers still use it and it is still used in some business applications (more are in C# these days though).

Pointers!

It will teach you how to use pointers. Pointers can save you memory and improve the speed of your program but more than anything you will learn a different point of view on how to write an application.

Memory Management

C# isn't going to teach you how to manage memory manually, ie:

Allocate memory in C++

MyClass *myObject = new MyClass();

Dealloc memory in C++

delete myObject;

It will blow up in your face

This is a good thing really (and probably applies to my point about pointers). C++ can be more difficult to program because you need to manage pointers, memory, write templates and many other reasons really. The error messages can be rather cryptic at times, but all of this will make you a much more defensive programmer and knowing C++ will help you to appreciate (or not) other languages more.

Learning the STL can be fun. I would start with vectors, lists, deques and iterators. If you ever need to program a game / game engine such as OGRE and run across one of these you will definitely need to learn how these work.

It is Cross Platform

When the hot job offer comes up for you one day to work for Nintendo, Sony or Blizzard, just remember that they write games in C++ not C# because the Wii, Playstation and Mac don't run on C#.

I believe that learning C++ is something everyone should do if they have the time because it is another useful tool in your toolkit, you will probably need to write some in your career anyway and knowing one of the most popular programming languages will only make you a better programmer.

Brock Woolf
Oops someone pressed send too soon. +1 for being so keen.
Justicle
I wouldn't try to scare people so much about memory management. With `auto_ptr` and more recently `shared_ptr`, it really isn't all that hard - not any harder than it was in VB6 (actually easier if you consider that VB6 didn't have weak pointers), and plenty of people managed that just fine.
Pavel Minaev
C is arguably a better language to understand pointers, memory layout and memory management. malloc() is clearer and more "real" than new MyClass(). C++ templates I am not sure anyone should learn - they are very specific to C++ and wasn't continued in any other language - seems like an evolutionary dead end. STL was nice back in the day but every modern language today has collection library and most are arguably better.I think there are better languages to learn unless one specifically wants to get a C++ job for some reason.
Gregory Mostizky
@Gregory. If you learn C++, learning C# isn't that different so I don't believe it is a waste to learn C++. And yes there are lots of people who need to write fast code and C++ is faster than C# and what modern games are written in. Fundamentally I don't think learning is a bad thing and if you do, you should probably rethink a career in programming.
Brock Woolf
@Brock Learning is a great thing and extremely important for anyone serious about software development. But it is impossible to learn everything so one must always choose - and frankly C++ is not a good choice today unless you want to get into C++ job specifically (such as game shop). If OP wants to learn about pointers he should learn C instead as it is much clearer and low level than C++. If he is interested in gaming I suggest he does some simple flash web game first to see if it's something he likes.
Gregory Mostizky
Well, I recommend learning C++ over C (you can do both at the same time anyway since C++ is a superset of C) rather than going straight for C.
Brock Woolf
`MyClass obj = new MyClass()` won't compile. You're missing an asterisk.
Mehrdad Afshari
@Mehrdad Of course! How did I miss that, especially since i'm constantly using pointers :)
Brock Woolf
@Brock I disagree. Gregory's got it spot on. Just because you program C++, doesn't mean you know much about programming C. That's a common misconception. I think if OP wants to go deep and learn some of the lower level stuff, why stop just near when there's a much better alternative right there?
mrduclaw
@mrduclaw I NEVER said if you learn C++ you know C. I said you can do both at the same time.
Brock Woolf
@Gregory: I'd say it's too early yet to tell where C++ templates are going. It's only recently that most compilers have really started to support them to the point where "modern c++" is starting to catch on. With the improvements coming in C++0x, that cover most of the worst pain-points of current templates, we may yet see other languages copying them.
Eclipse
The Wii, Playstation and Mac run C#. Like the XBox360. Bad argument.
Dykam
But they won't run XNA Code written in C#
Brock Woolf
A: 

C++ doesn't hold your hand, but it also allows you to shoot yourself in the foot! However, if you really want to get into gaming -which is a tough thing, I would strongly recommend that you go for C++. Here is another kinda similar question, you might wanna look at it too.

Galilyou
+9  A: 

If you want to get into game programming C++ is the language for you. Pretty much every game company exclusively uses C and C++. Take your time, it can take years to become very good at C++. Pointers, STL (especially algorithms), and templates are all difficult.

Read books for starting on C++. When you are better, read Effective C++ and More Effective C++.

rlbond
Related: http://stackoverflow.com/questions/931502/gaming-with-c-or-c
Liran Orevi
+3  A: 

You want to be in gaming, which sounds fun but has a reputation for being long long thankless hours ;-)

Gaming is in two levels:

The graphics engine is written in a very low-level way using a fairly low level language such as c/c++, and sometimes where performance is critical, assembler. But even when in c++, you have to understand how the graphics pipeline actually works in order to use it efficiently. So you have to join common sense, a deep understanding of hardware, the corner-cutting e.g. pointers of the language, and often a good bit of algorithm understanding to be competitive.

Much of the high level plot and level code is written in a scripting language such as Lua.

Not being a master of the low levels will risk that you aren't effective programming at either of these two levels.

C and C++ are worth learning as a way to understanding how computers (in their current form) work. Its also worth learning something even lower, such as an assembly language and learning about caches and such.

An understanding of how computers work and how to program them in C/C++ is an extremely underrated step up when using high level languages such as C#, VB, Java etc in any part of our industry. Joel on Software (real the whole site, its written by one of our hosts and its why so many programmers found stackoverflow in the first place) has talked extensively about this e.g. "all good programmers should be able to handle recursion and pointers, and that this is an excellent way to tell if someone is a good programmer"

Will
+13  A: 

It's not so much that C# holds your hand as that C++ pushes you out of a plane and says "fly".

C++ is a very popular language for a reason. It gets the job done and is incredibly flexible. It can be used for virtually any kind of application. However it's not specifically engineered for many scenarios that are popular today (like web apps).

I think the best approach is to figure out what you're doing and then pick the best language to solve that problem. C++ can be used to build web apps, but I'd probably choose C#/VB.Net + MVC since it's designed to solve that problem.

I think part of the reason that you see more 3rd party libraries out there for C++ is simply that it's an older language. Only time will tell this point though.

JaredPar
"It's not so much that C# holds your hand as that C++ pushes you out of a plane and says "fly"." This should definitely go in the "Best programming quotes" question :)
Edan Maor
+1  A: 

C++ is great when you know what you are doing. It is a multiparadigm language that doesn't force you into One True Way of doing things. This gives you enough rope to shoot yourself (and/or your team) in the foot. Moderate amount of discipline is advised.

After figuring out what RAII is all about I can never get used to garbage collected languages -- they simply remove features (deterministic lifetime control, essential for generic resource management) to solve one easy subproblem (automatic memory management).

Definitely learn enough about pointers to be comfortable regardless. It forces you to think about lifetime and owership of objects from the start and that's never a bad habit.

Eugene
A professor I had many moons ago used to use a quote for C++ that went "C gives you enough rope to hang yourself, C++ gives you the chair too."
NoMoreZealots
My favourite: "C makes it easy for you to shoot yourself in the foot. C++ makes it more difficult but, when you do, you blow your whole leg off." -- and I like C/C++!
Trevor Tippins
+3  A: 

You will not get a job as a programmer in the games industry without in-depth knowledge of C/C++. Period.

In games, if you are a tools or script programmer, there may be some requirement to learn C# or a scripting language.

Forget the hype about XNA, thats just the way it is today in the games industry.

Justicle
+4  A: 

Although I've never fully drunk the C++ cool-aid (which, back many years ago, may have been the reason I wasn't hired in Taligent, despite interviewing there... they HAD drunk said cool-aid;-), I have a pretty good command of the language and a grudging respect for it (partly nurtured through personal friendship with excellent C++ gurus like Matt Austern).

These days, my motto is "Python where I can, C++ where I must" -- and I've been pretty happy applying it for most of my programming (with occasional jaunts downwards into C or very occasionally assembly, midways into D, ObjC, Java, or C#, and up into [e.g.] bash, Haskell, Erlang, Boo, Scheme, Javascript, Scala, ... -- all of those are occasional adventures, C++ and Python, when all is said and done, are my daily bread and butter [and most of the jam too;-)]).

C++ is incredibly complicated and best applied as a subset through rigorous guidelines (these days I'm most familiar with google's, of course;-). But if proper discipline is observed C++ still has a lot to give you -- one of the best implementations of generic programming in a mainstream mostly-statically-typed language, good optimizers, high motivation to deal with "ownership issues" (for allocation/freeing) that garbage collected languages (almost all others;-) tend to push under the carpet (to occasional grief when resources aren't JUST easily-GC'd memory, ...).

For a soundbyte, you could say that C++ is the worst of all languages, except all the other languages which have been tried from time to time...;-)

Edit: just found a post from today (on a stockmarket-blogs aggregator site, of all places!-) which does an interesting job showing some economic consequences of choosing C++ vs Java for "deep server-side system infrastructure" projects -- it also has interesting links to similar analysis done by the Hypertable folks and others. Recommended reading for anybody who's sharing the doubts expressed in this question (though it would also help to see links about the costs -- in terms of programmer productivity, maintenance, time to market, etc -- of choosing C++ vs a higher-level language [esp. a garbage collected one like Java and most other modern languages], such comparisons are often hard to come by).

Alex Martelli
+1 for "C++ is best applied as a subset through rigorous guidelines", even if I must admit that, when I was learning python coming mostly from C++ I kept thinking "this language is incredibly bizarre" :)and compliments for the Churchill quote...
Paolo Tedesco
Do you know a language where rigour is not necessary?
Edouard A.
@Edouard A: English? ;)I think the problem with C++ is that there are often several reasonable-looking ways to achieve a goal, several of which aren't so reasonable when you know what you're doing. Contrast this with Python's "There should be one—and preferably only one—obvious way to do it" philosophy (which has sadly eroded a bit as the language has grown, but is still a good idea).
Kylotan
@Kylotan, Python shares this design goal with C (not C++): as "The Spirit of C" states -- see the preface to the C ISO standard, or http://www.artima.com/cppsource/spiritofc.html -- the ideal is to "Provide only one way to do an operation.".
Alex Martelli
I agree with orsogufo's comment, Python is Bizarre. I think people who started out with the "soft" languages like Python, just have a different way thinking to begin with. Much of Python doesn't feel "natural" to me.
NoMoreZealots
@Pete, I "started out" with Fortran IV -- Pascal, Lisp, Scheme, many assembly and microcode languages, C, PL/I, APL, Basic dialects, Rexx, Forth, Prolog, Modula-2, ksh, awk, C++, Perl, bash, and many others, followed in the course of the years (mentioning only those I did real work in, not those I just studied Python was roughly the 30th+ programming language I worked in after about 20 years of programing experience -- yet it soon became my very favorite of them all. I don't see how this chimes in with your hypothesis.
Alex Martelli
A: 

If theres one thing which will make you a complete programmer. Its C++ . One undergoes basic mathematics which starts with addition/subtraction, then linear equations, then 1D geometry, 2D, trigonometry, calculus. How many of us use these after we leave college. But these things make us smarter. Thats why they are taught world wide.

Same is the case with C++ .

pokrate
-1: No explanation on why you think C++ make you "a complete programmer". The math analogy does not make sense.
kigurai
+1  A: 

Java can do everything C# can do and more and it has amazing community around it with lots of active open source projects for almost all imaginable areas. Some might even say that there is too much choice in Java land.

If you want to get into gaming there are alternatives to C++, if you are willing to look into mobile games and/or web games. Java and Flash are languages that are used quite often on those platforms and on the plus side allow you to focus more on the content and actual game rather than on the internals and memory management, with the benefit of getting stuff working faster and with less effort.

You always want to use the best tool for the job. 10 years ago C++ was king and was a natural choice for almost everything. Today there are not many jobs where C++ is a natural fit. Web and business applications are controlled by scripting and managed languages, embedded is still mostly C as far as I know, which leaves C++ only high performance and large code base applications and there are just not many of those (except AAA game titles).

Gregory Mostizky
Why the downvote? A sane answer.
Will
Probably because someone is a microsoft fanboy and didn't like the harsh words against C#. +1 from me.
Brock Woolf
Probably because the first paragraph is completely irrelevant to the question being asked . Learning C++ is still a far better choice then either C# or Java if you want to get into the current games industry.
Ash
@Ash There is a lot more to game programming than just C++, especially since OP seems more interested in that as a hobby and not as in getting a job in the industry. One can argue that for a single person working in a free time developing small games in flash or java for web/mobile is much more interesting than trying to learn C++.
Gregory Mostizky
A: 

C++ is a cool language if you want to really torment yourself. But as for real-world usefulness, its creator's statement, "I believe most people have figured out for themselves that C++ is a waste of time", tells a lot. There are better alternatives nowadays.

Joonas Pulakka
The article you're linking is of course a joke: http://www.research.att.com/~bs/bs_faq.html#IEEE
Luc Touraille
What works for one, may not work for all. YMMV
spoulson
-1 for unreliable source, and ill founded information
Stowelly
+3  A: 

C++. while a horrible language (IMHO), is still worth learning because there is a lot of code floating around that uses it. The same applies to C. Personally the only reason I use C++ is

  1. My employer told me to, or the project I amw orking on uses it
  2. I am writing games (playing around with OGRE is kind of fun once you get the environment going, which was not entirely easy).
  3. For experience. For some reason it always makes me love writing Python code afterwards ;)
kigurai
A: 

I don't understand why such questions are allowed. They should be closed immediately.

Jagannath
+1  A: 

I know of no other language, as good as C++ or better, that you can distribute without worrying that the user does not have the runtime.

And, while all other runtimes can be easily installed (OK, for C# its not easy) you'd be shocked how many users just won't be able to get it.

And C++ is still very highly desirous in the workforce, it is fast and it is stable.

SamGoody
+1  A: 

As I understand it:

  • C is assembler with macros.
  • C++ is C with classes.
  • So, C++ is assembler with macros and classes.

For gaming performance, your code will determine whether the game is sluggish and not fun or crisp and fast action. For that, you need to be as close to bare metal as possible. In the old days game developers write direct to the hardware, but nowadays Windows provides DirectX as a shim for universal hardware compatibility. To get the most out of DirectX, you want to write in C++ to gain full control over how memory is managed and where your processor cycles go.

Sure, you can write DirectX-based games in C#. In fact, you should try it to get to know the APIs. However, C# is really a high level business language. Business apps are not especially dependent on UI performance.

spoulson
"So, C++ is assembler with macros and classes."but in reality c++ is assembler with templates, classes polymorphism, and type safety
Stowelly
Well damn, now you make it sound hard. :)
spoulson