7
votes
How Did You Learn C++?
I'm a beginner-ish at c++ and cannot find any good places to learn it. I tried learning from the books but they didn't help that much.
I'm a beginner-ish at c++ and cannot find any good places to learn it. I tried learning from the books but they didn't help that much.
So as a disclaimer, I don't know C++. I have, however, learned a bunch of different languages like C#, Python, Clojure, etc, both by self-study and through classes. I've never read a book or followed all the way through a tutorial, it just doesn't work for me.
The best way that I've found for myself to learn is to simply pick a project that's reasonably complex, but still doable at a beginner level, and finish it to the best of your ability. For C#, I made games in unity. For Python, I made little scripts and functions that would do whatever it was I wanted to do at the time.
For C++, I'd probably start with trying the traditional learning exercises like linked lists, binary search trees, and so on. That should get you a good grasp on how pointers and functions work, you get a chance to do something recursively if you want (you don't need to though!), and it should be totally doable with no knowledge and some Google-fu.
If there's something in particular you want to do with the language, I'd suggest splitting it into small parts and trying to get them all done individually. Modular development is a very useful skill, even if you're doing it on a much more granular scale than you normally would.
This really helps, thank you!
I've taught myself a couple languages by going through Project Euler problems and just looking up what I don't know how to do. After the first 20 or so, I'm usually comfortable with manipulating data structures, running loops, and defining functions.
Disclaimer: I am not a professional coder and my style is probably atrocious / horrendously suboptimal
Project Euler is 100% my go to for learning new languages. Nothing teaches you a new language better than trying to blast your way through their problems and googling syntax along the way. Great discussion for each problem with popular languages online as well.
The discussions for languages I'm using just underscore how amateur I am :(
but yeah, I feel a shitload more comfortable with Python after going through 20 PE problems. Much better than the Udemy course I was taking
To be fair, many PE problems tend to be more geared toward mathematics and crazy optimization. You can be a fairly good programmer and still struggle with some of their problems simply because you aren't familiar with those subjects to such a high degree.
For instance, take a look at problem 28. That's a problem that has a few possible solutions that come to mind:
Most people can get to solution #2 and solve the problem in a reasonable amount of time, but you'll find some people in the comments who have a lot of experience with math and will recognize that #3 exists and will know how to find it. That's not a mark against you, but a testament to their education in more advanced arithmetic.
Speaking of which, I love using #28 as a discussion point with interns. It's a great example of an obvious and terrible solution, a less-obvious but still intuitive solution that works out decently well, and a more difficult and subtle solution that completely blows the other solutions out of the water. It's a fantastic exercise for encouraging creative thinking about how to solve problems.
On that note, problem #67 is also one that I like to throw at interns. First I ask them about how they would solve it, and inevitably brute-forcing comes to mind pretty much immediately, but they get thrown for a loop once they're informed that it would take billions of years at best to solve the problem that way. Even better is when they're informed that a solution exists that can solve the problem in just fractions of a second!
CodeAcademy has a really great interactive Javascript tutorial. If you've never programmed before, I would go through something like that to get the basics of programming down. Then, once you've mastered the basics, switch over to C++ to learn its syntax and nuances by jumping in and programming small things.
Almost all languages are basically the same. Once you learn at least one really well, you can switch to almost any other one by just googling whenever you get stuck.
The problem I have with codecademy is that they hold your hand way too much. You can learn syntax and some really basic programming constructs, but it's way too easy to blow through their work without really understanding what you're doing. I would still recommend going to them first, but that should be followed up with small personal projects or another site like codingame to supplement that lack of enforced critical thinking.
This all depends on your level of expertise - do you know any other programming languages?
a tiny bit of java and python
So, while Tsubasa's advice is definitely good, there are some concepts in C++ that don't exist in either of those languages. You really want to get a good handle on pointers, pass-by-value vs pass-by-reference, memory management, and templates (kinda like Java generics, but different at a low level). Best way to really go about this is to read a bit about the concepts, and apply them in some way in a project or something you want to learn.
For the record, I learned C++ by making a terminal-based implementation of a boardgame. Think it was Pandemic, but it's been a while. Forced myself not to use any external libraries so I'd get a handle on memory management and pointers myself.
I learned it in college. It was the language used to teach all the programming concepts required for a Computer Science degree. If you're willing to give a book a try again, I would recommend an actual textbook, but make sure that you actually DO the problems at the end of each chapter. You probably don't need to do every single one but just do even or odd numbered ones.
The point is that you learn it by using it. Programming is also learning how to think in a programmatic sense. The hardest part is getting over that steep learning curve, but once you do it and understand it then basically any other language you try to pick up will be much easier. C++ is a very powerful language because while it is a high level language, it arguably is one of the "lowest levels" in the sense of how much control you can manage with the code at the bit level. Because of this aspect, it makes C++ one of the best languages to learn concepts with but it is a double-edged sword in that it is also one of the most complicated languages.