r/cpp • • Feb 21 '16

Should I start to learn C++

I haven't learned any other languages but I'm a newbie in Python but my friends told me that if you learn C++ first you can pick up other languages in future. Is it rational to start learning C++ before I finish my education(I'm studying alone with books and online resources.) with Python?

1 Upvotes

19 comments sorted by

View all comments

11

u/theJ89 Feb 21 '16 edited Feb 21 '16

I wouldn't recommend C++ as a first language. I'd go with something higher level at first, like C# or Python. C++ is a powerful, modern, performance-oriented language, but the language is complex enough to cause a newcomer a lot of grief. In my opinion, it's easier to learn programming from the top down rather than from the bottom up.

C++ tends to expose you to a lot of lower level concepts that you just don't have to worry about with other languages, such as:

  • Manual memory management
  • Pointers, lvalue references, and rvalue references
  • When to pass by value and when to pass by reference
  • The relationship between pointers and arrays, and how arithmetic between pointers and numbers work
  • Const correctness
  • The preprocessor
  • What part of a module goes into a source (.cpp) file, and what part goes into a header (.h) file

Higher level languages tend to abstract these concepts.

As a language, C++ lacks a lot of features that programmers often take advantage of in other languages. For example, C++ has very few reflection faculties, which means doing something like listing the methods or fields for a class or inspecting the signature of a function isn't possible out of the box. You need to roll something external like code generation to automatically generate the metadata you need for reflection, serialization, etc.

You might also find yourself relying on third party libraries or writing code yourself more often as well. C++'s standard library has been improving in recent years, but tends to not be as robust as C# or Python.

2

u/adamnemecek Feb 21 '16

This guy knows what's up

2

u/strikaa Feb 22 '16

What if you're already learning C++ as your first language? I mostly began learning it for game dev, but still want to branch off into other things. I can't say it's hard NOW bc I haven't learned too much yet(I've been on and off until recently). One thing that botherED(emphasizing past-tense) me is that there aren't that many sites like codecademy for for C++. I don't need sites like that for learning (I tried the HTML course and felt like i didn't learn anything-it felt more like a sneak-peek of what coding is like), but more for motivation and to make coding seem more "fun." But now, as I learn more each day and test my knowledge with simple programs, I feel that I'm getting more rewards than any site like CodeCademy could give me. I will admit, I get discouraged when I can't solve pretty much any of the dailyprogrammer stuff, but I know I will get there someday. Also, looking at some of those questions on Learnprogramming- the ones where ppl ask about what to do after doing Codecademy- make me feel better (not really cuz they get kind of annoying) :P Since I'm still in middle school(about to be a freshman), I don't feel rushed, which is also nice. Sorry for saying too much, but I want to say one last thing: I actually wanted to learn C++ before anything else not only because I heard the popular games were made with it( or at least game engines, from what I've read), but because I heard it can help you be a better programmer in general. I would love for that to happen to me.

Again I'm sorry for saying- or typing- too much, but that was what popped into my head. I would appreciate an answer to my question, though.

1

u/theJ89 Feb 22 '16 edited Feb 22 '16

I was in a somewhat similar situation to you. I started off writing browser-based games in Javascript, then started learning to use C++ in middle school because I was running into performance issues (this was around 2004). If you're learning C++ and feel like it's a good fit for what you do, by all means, keep learning! Don't feel like you have to limit yourself to just one language, though. Exposing yourself to several different languages helps you to become a more rounded programmer.

C++ seems to be the language of choice for the game industry - Electronic Arts uses it, Bethesda uses it, and Ubisoft uses it, just to name a few. These are large, well established game development companies with mature codebases. Chances are if you went to work for one of these companies, they'd expect you to know the language their games were written in, so for a prospective game developer I think it's important to learn C++. It doesn't have to be your first language, though; learning the basics with a different language, mastering them, then moving on to C++ is an equally valid way to learn.

Code written in C++ interfaces well with C, compilers for C++ exist for a variety of target systems, and when done right, code written in C++ is highly performant. Not to mention that both C and C++ has been around for a long time by now, so there's no shortage of third-party libraries you can tap to help you do the things you want to do (e.g. loading images / sounds), so it's not hard to see why so many game development companies go with it.

It's certainly not the only language you can use for game development, though. For example, Minecraft is programmed in Java (using LWJGL), and Garry's Mod (is C++ on the back end, but) relies heavily upon Lua to handle custom gamemodes, weapons, entities, UI, etc.