Learning C++ - Is this good to begin with?

Discussion in 'Computer Programming, Emulation, and Game Modding' started by Boy12, Aug 24, 2014.

  1. Boy12
    OP

    Boy12 NOT a new member!

    Member
    536
    134
    Mar 8, 2012
    Netherlands
    Purmerend
    Hello everybody who is reading this!
    So last week, i started learning C++, and i know some basic things like how variables work, etc,.
    I'm thinking of making a simple text based game, like " you see a door in front of you, do you enter or walk away" requiring the users input. To see if i learned things the good way, is this a simple project for starters, or do you guys recommend to make something more simple?
    Thanks in advance!
     
  2. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,698
    9,567
    Nov 21, 2005
    United Kingdom
    Basic text adventure is a good project, it may not get you far down the GUI path but for basic variables and acting upon them it is more than suitable.
    You may or may not want to look up linked lists before you set about it though (more for the text adventure concept), you can happily do without it but branching text adventure is what the linked list family of concepts handle quite well if you plan to expand the adventure any.
     
    Boy12 likes this.
  3. Issac

    Issac I

    Global Moderator
    GBAtemp Patron
    Issac is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    5,363
    2,641
    Apr 10, 2004
    Sweden
    Sweden
    I can't say it better than FAST6191... so yeah, what he said! :D It's a good start and absolutely nothing that's "over your head" or anything.
     
    Boy12 likes this.
  4. Boy12
    OP

    Boy12 NOT a new member!

    Member
    536
    134
    Mar 8, 2012
    Netherlands
    Purmerend
    Thank you very much!
     
  5. JoostinOnline

    JoostinOnline Certified Crash Test Dummy

    Member
    10,974
    3,758
    Apr 2, 2011
    United States
    The Twilight Zone
    C and C++ are very powerful languages, but they are also very difficult to start with. I started out with BASIC. When I started college and took CS1, I learned SCHEME (a very difficult and limited language) because it teaches you to stretch beyond the intended purposes of a function and write creative code. After that I took Java, which was a good next step, although often looked down. Now I program in C for homebrew, although it's entirely self-taught based on the previous mentioned languages.
     
  6. migles

    migles Mei the sexiest bae

    Member
    GBAtemp Patron
    migles is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    6,983
    4,701
    Sep 19, 2013
    Saint Kitts and Nevis
    my dad works for nintendo.
    Go north. You are in a forest. Go north. You are in a forest. Go north. You are in a forest. Oh dear, I believe I’m lost

    just because of this "joke" i spent 6 bucks on the game, and it was pretty fun

    take that; $1 iphone apps!
     
    vayanui8 likes this.
  7. Duo8

    Duo8 I don't like video games

    Member
    3,443
    1,140
    Jul 16, 2013
    A text adventure is my first python script too.
    I'm not creative so it sounds really dumb. And it's still not finished.
     
  8. Delta517

    Delta517 Its okay...Im a ninja ;)

    Member
    1,327
    35
    Nov 25, 2008
    Norway
    For me the best way to learn coding was just to fool around and make simple projects like small text games and calculator. I would say you are spot on! Just keep on trying to make stuff and after a while make even more complicated stuff. Good luck! :)
     
  9. Lucifer666

    Lucifer666 all the world needs is me

    Member
    1,495
    732
    Apr 22, 2011
    The Fourth Dimension
    Yep! What Delta517 said is exactly how I learned C++

    I just tried to incorporate some variables, operations and if statements to make simple things like calculators and text adventures. You get used to the syntax more. I also bought books which have really helped me. (If you're going down that route I'd recommend SAMS Teach Yourself C++ in an Hour a Day)
     
  10. Tom Bombadildo

    Tom Bombadildo Honk!

    pip Contributor
    GBAtemp Patron
    Tom Bombadildo is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    10,795
    10,900
    Jul 11, 2009
    United States
    I forgot
    Joostin also makes a good point, starting straight out with C/C++ is quite difficult for beginners (if that's what you are).

    I and most others would recommend starting out with Python first, it's quite easy to learn compared to C/C++.
     
    Boy12 likes this.
  11. Dimensional

    Dimensional GBAtemp Advanced Fan

    Member
    614
    93
    Dec 7, 2008
    United States
    Texas
    C++ was the first programming language I ever messed with. The very basic Hello World Program is what helped me get started, and it's used in all kinds of languages to get you started in them. Since most of them share similar structures, like C++ and Java, you can learn some things in one language and have little difficulty rewriting it in another language. But those are the high level programming languages, not some scripting language, which tends to have it's own way of doing things.

    Still, it's a good thing to see you taking initiative and learning how to program and make a text based adventure game. Like FAST6191 said, you should look into link listing, also known as method and functions in some languages, as it allows you to cut down on code repetition and makes it easier for you to do more with your keyboard inputs. Without it, you can only press a key when the code allows it. With it, you can basically make your key input the center of the program, and everything else just be called via switch statements and methods to ensure a proper text adventure. Useful for when you want to look at your inventory or read a map.

    Just remember that a game is basically just a program with it's entire running code inside an infinite loop, and a specific condition or keyboard key will terminate the loop to be able to properly exit the program.
     
    Boy12 likes this.
  12. Boy12
    OP

    Boy12 NOT a new member!

    Member
    536
    134
    Mar 8, 2012
    Netherlands
    Purmerend
    Thanks for the info.
    I did learn python 2 years ago, though.
    Also, one more question: right now i learn some things here and there. Like, if i want to know variables, i learn variables.
    If i want to learn statements, i learn them.

    Is that a good way to learn, or a bad way to learn C++?
     
  13. Dimensional

    Dimensional GBAtemp Advanced Fan

    Member
    614
    93
    Dec 7, 2008
    United States
    Texas
    Python is more of a scripting language than a programming language. So it's not really the same. But that doesn't mean you shouldn't give up on one or the other. It's good to know things like this. Just don't be surprised if what you're trying to do doesn't work because it's not the same in the other language.

    Some things I recommend you research are do_while statements, switches and cases, methods which are things like main(), and possibly classes, as you can use all of those to make a pretty good text game. Plus with classes, you can basically create a set structure for things like the inventory. For more advanced tricks, see about making the game save where you are, what you've done, what you have, etc.

    You'd have to have what I call a Game Switch for various ingame events that you want to have achieved, which also can help out if your game has a path of events the player must go through in order to beat the game, like slaying the dragon to free the princess, or crossing the bridge to get the sword that'll slay the dragon. You'd need a switch for getting the sword, and another for slaying the dragon, so that when you save and return to right where you were last, and not have to get the sword or slay the dragon again.
     
  14. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,594
    21,610
    Sep 13, 2009
    Poland
    Gaming Grotto
    The thing with starting with easy languages instead of C/C++ is that it's completely disposable knowledge. You learn the basic concepts, but you will never use the language again, so what's the point? I started with C and I have no regrets.
     
    YoshiInAVoid, Issac and Dork like this.
  15. cracker

    cracker Nyah!

    Member
    3,163
    459
    Aug 24, 2005
    United States
    The books that really helped me were Dummies books and numerous old school C/++ programming books (DOS). Though, just as much or even more so -- taking others' source code and altering it to see what would happen when I would run it. The latter can keep you more engaged on the learning process as long as you don't overwhelm yourself with too much source code to wade through. When you hit a piece of code that you don't understand then research it until you do. Don't be afraid to push the limits when you have a handle on the simpler things and Google is your friend when you want to know how to do certain things that you can't easily reference in a book like how do I parse an input string in c++. Join a c/++ forum for when you are stuck and/or shit hits the fan (because it will) and keep backups before major changes to your source. Good luck!
     
    Psionic Roshambo likes this.
  16. boomario

    boomario Nothing to say here.

    Member
    412
    135
    Oct 31, 2012
    Brazil
    I'm also starting with c++ and i recommend you keep trying because it seriously worth it, there is a lot of languages based on c out there. :lol:
     
  17. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,698
    9,567
    Nov 21, 2005
    United Kingdom
    Is that really a distinction we make these days? I have as much of a giggle as anybody when they come up and tell me that know programming by virtue of knowing HTML, however Python is Turing complete, and not even some crazy esoteric way, and can hang with the low level file/data format manipulation crowd. Now a Python type might have hazy ideas at best on memory management, memory safety and pointers (as the C family knows them) but scripting vs compiled does not especially seem like something worth noting.

    As for learning piece by piece... I would not say it is ideal. Such things tend to see you missing out on one or more core concepts and not know enough to know what you have missed, such things are why some dislike self taught programmers. Of course you also have the people that "were away that day when they taught that" so it is not universal and there are entire degree level programs in online video form (for free, possibly even allowing you to get a reasonably worthwhile cert at the end if you really want) so you can have the best of both worlds. If we are suggesting books I do not really have any I can point at for C++ (mainly as I am not great at C++ compared to C or something else entirely), however I really did like the apress beginning series for all the various languages/concepts I have read them in (quite a few at this point) and their one for C is the one I suggest to this day.
     
  18. Arras

    Arras GBAtemp Guru

    Member
    5,878
    2,710
    Sep 14, 2010
    Netherlands
    Idk, learning the basic concepts, structures, how to use and apply them is fairly useful and universal knowledge in my book. By that logic learning something weird like Haskell (my university made me do this) is useless too since you will never use the language again. However, turns out it actually influences how you work in other languages and teaches you some neat things too.
     
    cracker likes this.
  19. cracker

    cracker Nyah!

    Member
    3,163
    459
    Aug 24, 2005
    United States
    That's very true. I learn new things all the time by similar concepts/functions that translate to other languages.
     
  20. Supercool330

    Supercool330 GBAtemp Advanced Fan

    Member
    687
    140
    Sep 28, 2008
    United States
    Ya, I have to say, I agree with the start with python advice. C++ is a very complex language (especially if you are using all the C++14 stuff, which you should be as it can produce way more elegant code), and learning a simpler language first can introduce you to many of the concepts such as variables, indirection, data structures, iteration, recursion, algorithms, closures, and functional programming without all of the syntax, compiling, and linking overhead. A lot of amateur programmers (and more professional programmers than you might expect) think that all they need to do to write code is learn the syntax, but you really need to learn basic programming paradigms (which apply to all languages), and then learn the dao (the "way") of the specific language. I would advise starting with Python or Scheme. Scheme is unfortunately not a very useful language; dialects of LISP (Scheme is a LISP dialect) are used in academia for AI prototyping, and in some distributed systems research, but other technologies are more popular for these problems in industry. The plus side to Scheme is that it has essentially no syntax, and so there is very little overhead in jumping right in and learning actual programming paradigms. Python on the other hand is a very useful language; it is fairly popular in industry, and is common in community projects as well. It has more syntax than Scheme (and by extension, the right way of doing things is sometimes complex), but it is still a lot simpler than C++, and is overall a good place to start.

    As for the self taught vs class taught programmers discussion, they can definitely both be shit. Unfortunately, at the end of the day, what I have found is that being a good programmer requires two things: the right mindset, and experience. I've been programming for over 80% of my life, and still, when I look at stuff I did even two or three years ago, I think some of it is shit. The best way to learn to be a good programmer is to program, and ideally get code reviews from other good programmers. I suspect that the first good piece of code I ever wrote was during my second year as an intern during college (BTW, most grad students in CS write TERRIBLE code, it is astounding). As for the mindset, I think it requires a certain predisposition for algorithmic and structured thinking. Most people can sort a deck of cards, but would be completely unable to describe the process algorithmically, and define the structure of the auxiliary information that they keep in their head while doing it. Being a good programmer also requires a certain degree of laziness. If you find some problem that seems really hard, or you feel like you are doing a lot of work to get something to function, you are probably doing it sub-optimally and need to reduce the problem, or rethink the solution. Finally, I think it requires a certain degree of perfectionism. The compulsion to write elegant, concise, and efficient code is essential to avoid accepting bad, redundant, inefficient, unmaintainable code that "gets the job done" (anytime anybody ever says "but it works" as a reason not to rewrite/refactor something, I have desire to punch them in the face).

    tl;dr: My advice is to start coding early and often, accept that EVERYTHING you are doing is wrong, but at least you will learn the basics. Then, if you like it, study computer science in school, which will do you very little good in the real world, but will at least give you a decent background in theory. Then, get a job as a programmer at a real company (not a shitty start up), where they have good programming practices like code reviews, unit tests, universal source control and build infrastructure, etc. After doing this for a few years, you will probably be a decent programmer.