When to learn c++?

Started by
11 comments, last by iskatsu 10 years, 7 months ago

Let me start off by saying I know the "Should I learn c++?" question has been done to death. I'm aware of the pros and cons stated by multitudes of folks on the internet. However, the answer to my question, alluded to in the title, has come up empty me in a google and forums search so I figured I would start a thread on it.

Question: When should I start to learn c++?

That's the brief version, and if you want to, you can stop there and give a general answer to when someone should venture into the land of c++. And I'd like to thank you in advance for any reply or advice you can give. However, for those who wish to know more specifics of my case, I'd like to provide some of my personal history that may aid in determining what advice to give me. I hope this does not become a giant wall of text.

I have grown up around computers, my dad did some programming in fortran, pascal, basic, and some CNC languages when I was a kid. So we've always had a computer around that I was able to mess around on. I started with some pascal myself, then later ventured into javascript when I wanted to do some web stuff. In the early 2000s, I was enrolled in a computer science program at a college near me. They started us in Visual Basic and a little c++, though in c++ I didn't get much past cin/cout. I had to drop out due to financial and personal reasons. Later, I was able to go to a different college and finish a degree, but since the closest they had to CS was electrical engineering, which didn't really hold my attention, I ended up getting a BS in physics. I use python regularly for computational physics problems, and I feel comfortable enough with python that I feel that if I'm given something to program, even if I'm not familiar with the modules to do it with, I could delve into the documentation and find a way to do it. It may not be elegant, short, or efficient, but I feel I could find a solution. I am by no means an expert in python, there is far too much that I don't know in python to convincingly claim to be, but I feel I know enough at least to be dangerous, as the saying goes.

Lately though, I have been dabbling in C, mostly just taking old programs I've written in python to see if I can make them work in C, and get the same results. Ostensibly to see if there is a computation time benefit to learning C, but mostly to start learning it just because I'm a little curious about it and have the time. I have done a little game programming in python, mostly just the standard hangman, tic-tac-toe, and text based games. I haven't dabbled too much in pygame because I don't like it, I don't know where my dislike for pygame stems, could be the obnoxious colour of the pygame website, could be the overuse of underscores in method names, I'm not sure, but I'm just not a fan.

Obviously, with this history, I'm not just starting out learning to program, and I'm comfortable enough to say that I could probably pick up c++, so I'm not worried about can I learn it. I also know that at 30, with no real formal training in CS, and at this point, no real portfolio to speak of, at least that I'd be proud enough to share with a prospective employer, me becoming employed at a AAA studio, and actually needing c++, is really unlikely to happen.

Since I doubt that I will realistically ever need the lower level and efficiency of c++, is it even worth it to try to learn c++, or would I be better off just messing around with c# and an engine like Unity or something of the sorts? Furthermore, since I'm already trying to learn C for scientific computing purposes, would it be better to just learn c++ for that since that's just a superset of C anyways?

Thank you for taking the time to read this.

-Jared

Advertisement

I'd say... anytime you want.

I started with Java/C# and web development, and when I decided to make a game I decided to use C/C++ since I considered it as the "main" language for programming games.

It's been nearly a year or two that I started, and I'm quite glad I did.

I still haven't got nowhere near getting a complete game, where I probably would have if I sticked to XNA (unfortunately deceased) or Unity, but I got to learn so many things about computers, graphics, languages and hardware in general, how they work, and this helped gave me conviction that I can manage to get anything, anywhere.

Lines I used to see often in C# such as:

MyClass mA = new MyClass();
MyClass mB = mA;

Now give me some shock before I realize "Oh, it's C#".

So, for knowledge I think it was a good thing, but for production value x time spent, not so much.

If you want to develop games and only focus on developing games, I'd recommend to stick to using an existing engine or learning C++ just for using the minimum required for these.

Another thing is, there's just too much about C++. Learning the syntax might take less than a day, it's techniques and such less than a week, but that alone isn't much, really. Learning C++ I think it's learning how things work and studying constantly for new things, how a certain app works, how you use a certain library, etc

As for C or C++, please disregard C completely.

In the past year that I started learning it, I was completely fixed on the idea that I wasn't going to use strings at all. I had (still have) the idea that with better functionality comes worse performance, so I always used char pointers (array of chars to represent strings), among other things.

After various questions and tutorials I've read around, I noticed how silly that was. In some (most, actually) cases the C++ classes and containers were even BETTER than my C implementations.

Now, the language has been upgraded to C++11, so there's a bunch of new stuff and I'm still going through the same thing. Should I use the new features, are they better? Are they worse?

I'll keep coding in C++, and I'll be slowly changing towards C++11 as I see these new features aren't so bad as I think (and I'm pretty sure they aren't).


Since I doubt that I will realistically ever need the lower level and efficiency of c++, is it even worth it to try to learn c++, or would I be better off just messing around with c# and an engine like Unity or something of the sorts?

Is it worth it is a personal question. Is it worth it FOR YOU?

Good game programmers will learn many languages. C++ is generally one of those languages. Other frequently used programming languages include Java, C#, Python, Perl, JavaScript, SQL, PHP, Ruby, ActionScript, and shell languages. Markup languages you will likely want to learn include things like HTML, XML, JSON and YAML. Neither is an all-encompassing list. Some languages are good to know in depth, others will require just a cursory understanding; talented professional programmers will end up knowing twenty, thirty, fifty, or more programming languages over their entire career.

The order you learn them is not very important, although some are much easier to learn that others.

If you intend to work on game consoles and game engines you will need to know C++ before you get the job. If you intend to develop any high performance software, including game servers, you will need to know C++ before you get the job.

If you intend to work on web games in JavaScript or Flash or Java Applets you might never look at C++ code.

Furthermore, since I'm already trying to learn C for scientific computing purposes, would it be better to just learn c++ for that since that's just a superset of C anyways?

Let's clear that up for you.

C and C++ do not have a superset/subset relationship. There was a time in the 1980s right after C++ was created that you could run C code through a C++ compiler, but those days are long gone. Any significant C code is incompatible with C++ code and will generate large numbers of errors in a C++ compiler.

Implicit conversions through void pointers, boolean values, tentative definitions, implicit casts, VLAs, designated initializers, and many other differences make code that is valid C not compile in a C++ compiler. The simple act of making an object with malloc() through C idioms will result in a compiler error in C++.

C and C++ are different languages. They had a common ancestor but diverged almost 30 years ago.


mostly to start learning it just because I'm a little curious about it and have the time.

That's all the reason you need.

"me becoming employed at a AAA studio, and actually needing c++, is really unlikely to happen"

I dont work in the industry (Still a student), but I would have to say I disagree with the above statement.

I have no idea what your physics degree consisted of, but I guess you have a solid understanding of motion, forces, vecotrs, etc. In addition, you may have all sorts of maths knowledge which applies to 3D games / graphics / physics engines. At the very least, you will easily be able to learn the 3D math stuff - and at a *MUCH* better level than a student. Maths is a key skill in the games industry without a doubt. Mathemetics For 3D Games Programming and Computer Graphics by Eric Lengyel is a good place to start looking/comparing your skill sets.

Personally (as I did in formal education) I would start with C (Being able to make some console apps/games) and then learn C++. C and C++ are similar and most books dont go in to classes from chapter one (Unlike Objective C, for example, which is a class heavy language).

From their, the world is your oyster. You can apply your degree and aim to develop some physics systems. Can learn Direct3D/Open GL and go down the graphics route. Learn sound programming, networking, etc.

No Games Programming degree/Computer Science degree can teach everything. Mine teaches C++ and thats literally about it (and we have a decent employment rate within the first 6 months). The best games programming degree in the UK (Teesside if im not mistaken) hasnt tought any content that I havnt been able to do in 4/5 months of studying Direct3D11 by myself (And I would say that learning something yourself is more important than the degree - indeed, everyone I have spoke too says the first question in an interview centers around things you do outside of education. Plus, imo, teaching something yourself gives you a much more rounded knowledge whenever you finally get it. Uni has wayyyyy too much hand holding to be good for you).

My mate did Computer Science (Newcastle) and, well... I wasn't impressed tbh. Defenatly not for games programming anyway.

So yeah, why not? If your looking for a career change, then your not in a terrible position. Most junior jobs state that they are looking for people with "Computer Science (and games programming) or maths related degree" - You do have a maths related degree.

Finally, learning c++ and games related programming can take time to do correctly. C++ is a hard language. Its of course worth noting that learning C++ as a second language is MUCH easier than it being your first. C#/Java (I did objective C. But I'm a mini mac fanboy tongue.png ) I have heard is a good start if you want another langauge first .


C and C++ do not have a superset/subset relationship. There was a time in the 1980s right after C++ was created that you could run C code through a C++ compiler, but those days are long gone. Any significant C code is incompatible with C++ code and will generate large numbers of errors in a C++ compiler.

are you sure about that?

CAVEMAN is 70,000+ lines of C code, compiled in MS Visual Studio C++ 2012, warning level 4 (to suppress inline-ing notifications), zero errors, zero warnings.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php


The simple act of making an object with malloc() through C idioms will result in a compiler error in C++.

object, or just a buffer?

buffer works fine:


 
 
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
 
unsigned char *p;
 
nCmdShow=0;
lpCmdLine=0;
hPrevInstance=0;
if (!initprog(hInstance)) { Zmsg("Error initializing program","Caveman v3.0"); return(1); }
 
p=(unsigned char *)malloc(1000);
free(p);
 
titlescreen();
runprog();
Zshutdown();
PostQuitMessage(0);
return(0);
}
 

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Please reread what was actually written:

would it be better to just learn c++ for that since that's just a superset of C anyways?

C and C++ do not have a superset/subset relationship.

For C++ to be a superset of C, then any valid C program must also be a valid C++ program.

Such is not the case. Earlier I listed just a few examples of things that are present in C that will not work in a C++ compiler. A web search can find many more differences.

Yes it is possible for people to use a constrained portion of the C language, add a bunch of casts that would be unnecessary in C but are required in C++, and write code that can compile in both. But it is also possible for me to write functions that I can copy/paste into Java, C#, python, and other languages. That establishes that the languages are similar, but not that it is a subset.

For example, in that code listing:

p=(unsigned char *)malloc(1000);

That cast is not a C idiom. There is no reason for a C programmer to write that cast. It was written only to shoehorn the code into a C++ compiler.

Frequent variable names in C include "new" and "old", that would break in C++. Occasionally when I work in C I will have names like "template" only to remember that the name is a keyword in C++ and shouldn't be used.

That's not to say you cannot write large programs that are constrained to work with multiple languages. With carefully-crafted constrained writing people have done exactly that. Just as people have also written constrained books like Gadsby without the letter E, or The Exeter Text that only uses the vowel E; yet you wouldn't claim that because of those books the English language does not have those vowels. Just because someone chooses to constrain their writing to a subset of the language does not mean that the properties of their constraints apply to the language as a whole.


C and C++ do not have a superset/subset relationship. There was a time in the 1980s right after C++ was created that you could run C code through a C++ compiler, but those days are long gone. Any significant C code is incompatible with C++ code and will generate large numbers of errors in a C++ compiler.

are you sure about that?

CAVEMAN is 70,000+ lines of C code, compiled in MS Visual Studio C++ 2012, warning level 4 (to suppress inline-ing notifications), zero errors, zero warnings.

msvc++ will use a C89 compiler to compile any files with a .c extension (if you mix in c++ code it will most likely fail to compile, if you tell the compiler explicitly to compile it as c++ it will most likely fail, and if you rename the files to *.cpp or *.cc it will most likely fail to compile (unless you explicitly tell it to compile the file as C89 despite the .cpp file extension)

gcc will do the same thing for C,C++,Objective-C, Objective-C++, Ada and Fortran (Fortran most definitely is not a subset of C or C++)

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

That cast is not a C idiom. There is no reason for a C programmer to write that cast. It was written only to shoehorn the code into a C++ compiler.

so then i'm not doing c code, i'm doing c++ without the oo extensions? now i'm confused... blink.png

trying to remember when i learned c, and what compiler...

it was for school, systems i think, you had to write a vm, a compiler, a linker, and a loader in C, and you had to learn C on your own. they taught you pascal and figured you could figure out the rest. kinda weird, because while there i was also taught stuff like forth, smalltalk, lisp, motorola 68000 assembler, fortran, cobol, god the list just goes on. worked out ok though, i got an A in the class.

ok, the C was on a sun sparc workstation running bsd unix and x11 windows. does that sound right?

and an Emacs editor, and GNU C (i think).

then for games, i switched from borland pascal 7 to i guess borland C (or c++ ?) v4 (?). then i switched to watcom. then microsoft.

but as i recall, i switched to C for games before the C++ extensions came along.

so would borland c 4.0 be c or c++ ?

seems to me i've been writing exactly the same code since i switched from pascal to C (++ ?) for games. its not like the stuff stopped working when the c++ compilers came out. or perhaps they needed a mod or cast or two, been a long time.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php


msvc++ will use a C89 compiler to compile any files with a .c extension (if you mix in c++ code it will most likely fail to compile, if you tell the compiler explicitly to compile it as c++ it will most likely fail, and if you rename the files to *.cpp or *.cc it will most likely fail to compile (unless you explicitly tell it to compile the file as C89 despite the .cpp file extension)

i use .cpp and .h, and in the compiler settings i tell it to compile as c++ code (for the stronger type checking).

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement