Jump to content

Tips for a C++ Beginner?

DrDerp

Hello, I am on a FIRST Robotics Competition team and am beginning to learn C++. Any tips for me? What I'm doing is pretty simple stuff (programming robots) compared to a lot of projects, but any tips are welcome! Thanks!

Who needs fancy graphics and high resolutions when you can get a 60 FPS frame rate on iGPUs?

Link to comment
Share on other sites

Link to post
Share on other sites

System

  • CPU
    Ryzen 1600x
  • Motherboard
    ASUS ROG STRIX B350-F
  • RAM
    16gb trident z RGB 3000 mhz
  • GPU
    1070ti Msi Twin Frozer
  • Case
    CoolerMaster Maker 5
  • Storage
    850 Evo 250gb Qty:2
  • PSU
    EVGA SuperNova G1 Watt:650
  • Display(s)
    1 Acer 24in 60hz, 1 Acer 24in 144hz
  • Cooling
    NZXT kraken x62 rev2, NZXT AER RGB 140mm Qty:5, CableMod 30cm RGB strip Qty:2
  • Keyboard
    K551 VARA by Redragon 104 Key RGB
  • Mouse
    Redragon M601 Gaming Mouse
Link to comment
Share on other sites

Link to post
Share on other sites

Having just started learning C the best thing you can do is just start. I found the online tutorials bad. I hate reading(Dam dyslexia) and I can't stand watching someone else do it on a video. Think of something you want a program to do, for example you could make a program that searches an array for a word. A program that reverses a sentence. As long as the first thing you do is get an output that says "Hello world". 

Have you tried turning it off and on again?

Link to comment
Share on other sites

Link to post
Share on other sites

Here's my list of recommendations to get started:

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, DrDerp said:

Any tips for me?

Invest just as much time in learning the theory as in learning a given language, and do so as early as is possible.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

On 12/20/2017 at 9:09 AM, DrDerp said:

Hello, I am on a FIRST Robotics Competition team and am beginning to learn C++. Any tips for me? What I'm doing is pretty simple stuff (programming robots) compared to a lot of projects, but any tips are welcome! Thanks!

Get competitive on https://projecteuler.net/

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, straight_stewie said:

Get competitive on https://projecteuler.net/

I like Codewars as one can find challenges that are more varied and 'real world' applicable.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Hey, it's great to see that you are eager to get involved with c++. It really highlights the importance of these kind of clubs.

 

I learned some c++ while at university, but I honestly didn't get a good grasp on what it was all about until I started using it everyday for work. 

 

Some tips:

  • Start with small projects that can be solved in 30-60 mins, then work your way up to more involved problems.
  • Keep a record of all your completed projects and source code, you have no idea how many times you will look back to see how you solved a problem.
  • Focus on the programming fundamentals rather than the language syntax. You will learn the language with time and google, study the fundamentals first as you can apply them to any situation.
  • Avoid tutorials where you copy code from an instructor, online courses are terrible for this. Programming is a practical exercise, you learn by doing. If you were learning to play an instrument, you would not watch 100 hours of videos before trying it yourself.

You have a great opportunity here to develop your skills and have fun while doing it, good luck in your project!

Link to comment
Share on other sites

Link to post
Share on other sites

Start making stuff but try to limit the scale of what your making to stuff you could complete within a day.

 

Small projects are much better than a massive project when you're first learning a new skill since by the time complete a large project you'll have learned enough that you'll be tempted to go back and "fix" all the mistakes you've made. This wastes a lot of time during which you're not really learning anything but rather just blindly redoing stuff. Additionally redoing things can get really boring which can contribute to a loss of motivation.

 

Some example projects I can think of, off the top of my head:

  • Sort an array using a couple sorting algorithms (this will also help you understand how sorting works, Also you could just use vectors to store data in array like structures since it makes things much easier but it's good to also know how static arrays work)
  • Compute Fibonacci numbers (basically just a formula but there's an optimization you can do to make it faster)
  • Find x by solving ax^2+bx+c=0 with the quadratic formula (also just a formula but it's rather useful. Recently had to use it to figure out if a ray hit a sphere when implementing a ray tracer. Initially just give it a,b,c without the full expression but you could try figuring out how to extract a,b,c from a string expression... although string manipulation of that kind typically isn't that useful and requires a lot of effort, especially if you're a beginner)
  • You could even try some text based games, I've written tic tac toe in python and made it work both through a gui and a console. The issue with gui's in general is that they're not the easiest thing to work with.
  • Most guis use events of some kind which aren't the easiest to understand for a beginner, especially within a language that as far as I can tell doesn't have a standard library for them. So while guis are fun and satisfying when they work, the rather steep learning curve is certainly there. If you really want a gui I'd suggest using something simple like turtle graphics (which I just googled and turns out exists in C++, I only ever used it in python) for drawing stuff to the screen.
  • Fractals are really neat and can be rather simple to implement but often require recursion and some kind of gui or saving them to a file is required to actually see what your program made. (Computerphile recently posted a really cool video on fractals)

Anyway the main thing is practice by making something! Preferably that something is fun but often times the beginning stages of learning are dreadful so don't lose motivation since eventually you will get to a stage where you can do really cool stuff.

 

Also just as a general rule, always try to write good code that those you're working with, or even yourself after a few days had passed, will be able to understand. Comments help but comments can only go so far. If you're code is a mess the comments will just make things even more cluttered. And that's assuming the comments aren't outdated... Basically don't do any of the stuff described here https://github.com/Droogans/unmaintainable-code

 

Lastly, if you have never programmed before, then I'm not sure I'd be able to endorse starting with C++. If you can I'd recommend learning/using Python, C# or even Java. Don't get me wrong, C++ is great, it's basically my favorite language now that I know it but it's got a lot of features and can be difficult to learn. Especially if you’ve got no prior background to draw on. When I was learning C++, I knew what I wanted to do and just needed to figure out how to do the thing I wanted to do within C++. I'm not sure I'd have been motivated enough to learn C++ if I had to figure out both what to do and how to do it... Also, if you're interested, in my case I basically learned C++ as a side effect of learning OpenGL by mainly using https://learnopengl.com/ which is a really awesome resource.

 

 

Edit: Oh and try to avoid tutorials where the "teacher" just reads the code they're typing or saying what the content of the line they'll write is. It's much more valuable to know why they are doing something rather than just a blind "do this, now do this, next do this..." (cough a Qt video tutorial I watched yesterday in a nutshell). Also if there's room for creativity in a tutorial you're following, try to be creative. That'll help avoid just blatant copying without actually understanding what's going on. Although at the same time don't be afraid to just copy someone else code and moving on. Try to not get stuck on a single concept. In fact often times it's not only perfectly okay to skip it but doing so may result in you actually understanding it whereas if you just focused on it you'd get bored and never actually get past it.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×