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

Boy12

NOT a new member!
OP
Member
Joined
Mar 8, 2012
Messages
536
Trophies
0
Location
Purmerend
XP
459
Country
Netherlands
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!
 

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
36,798
Trophies
3
XP
28,321
Country
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.
 
  • Like
Reactions: Boy12

Issac

Iᔕᔕᗩᑕ
Supervisor
Joined
Apr 10, 2004
Messages
7,025
Trophies
3
Location
Sweden
XP
7,346
Country
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.
 
  • Like
Reactions: Boy12

Boy12

NOT a new member!
OP
Member
Joined
Mar 8, 2012
Messages
536
Trophies
0
Location
Purmerend
XP
459
Country
Netherlands
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.

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.

Thank you very much!
 

JoostinOnline

Certified Crash Test Dummy
Member
Joined
Apr 2, 2011
Messages
11,005
Trophies
1
Location
The Twilight Zone
Website
www.hacksden.com
XP
4,339
Country
United States
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.
 

migles

All my gbatemp friends are now mods, except for me
Member
Joined
Sep 19, 2013
Messages
8,033
Trophies
0
Location
Earth-chan
XP
5,299
Country
China
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!
 
  • Like
Reactions: vayanui8

Duo8

Well-Known Member
Member
Joined
Jul 16, 2013
Messages
3,613
Trophies
2
XP
3,024
Country
Vietnam
A text adventure is my first python script too.
I'm not creative so it sounds really dumb. And it's still not finished.
 

Delta517

Its okay...Im a ninja ;)
Member
Joined
Nov 25, 2008
Messages
1,329
Trophies
0
Age
29
Website
Visit site
XP
1,180
Country
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! :)
 

Lucifer666

all the world needs is me
Member
Joined
Apr 22, 2011
Messages
1,626
Trophies
1
Location
The Fourth Dimension
XP
2,160
Country
United Kingdom
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)
 

Tom Bombadildo

Dick, With Balls
Member
Joined
Jul 11, 2009
Messages
14,575
Trophies
2
Age
29
Location
I forgot
Website
POCKET.LIKEITS
XP
19,226
Country
United States
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++.
 
  • Like
Reactions: Boy12

Dimensional

Well-Known Member
Member
Joined
Dec 7, 2008
Messages
1,008
Trophies
1
Age
34
Location
Texas
XP
2,784
Country
United States
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.
 
  • Like
Reactions: Boy12

Boy12

NOT a new member!
OP
Member
Joined
Mar 8, 2012
Messages
536
Trophies
0
Location
Purmerend
XP
459
Country
Netherlands
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++.
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++.
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++?
 

Dimensional

Well-Known Member
Member
Joined
Dec 7, 2008
Messages
1,008
Trophies
1
Age
34
Location
Texas
XP
2,784
Country
United States
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++?

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.
 

cracker

Nyah!
Member
Joined
Aug 24, 2005
Messages
3,619
Trophies
1
XP
2,213
Country
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!
 
  • Like
Reactions: Psionic Roshambo

boomario

Well-Known Member
Member
Joined
Oct 31, 2012
Messages
449
Trophies
1
XP
2,246
Country
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:
 

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
36,798
Trophies
3
XP
28,321
Country
United Kingdom
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.

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.
 

Arras

Well-Known Member
Member
Joined
Sep 14, 2010
Messages
6,318
Trophies
2
XP
5,409
Country
Netherlands
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.
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.
 
  • Like
Reactions: cracker

Supercool330

Well-Known Member
Member
Joined
Sep 28, 2008
Messages
752
Trophies
1
XP
1,129
Country
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.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    SylverReZ @ SylverReZ: @OctoAori20, Thank you. Hope you're in good spirits today like I am. :)