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

  • Thread starter Thread starter Boy12
  • Start date Start date
  • Views Views 7,693
  • Replies Replies 63
basic text-based game is easy mode. you don't even need to get into the pointer hell in order to do that.
Simply cin and cout and if/switch statements will get you what you want.
So yes I have to say that making a text based game is perfect.
Depending on how advanced you want it ofcourse :)

I myself started with basic
then went to turbo pascal
then to c
then to php
then to c++
then to c#
then to asp.net

C# is my personal preference thanks to all the ease & help you get when writing your code. But since C++ is the most common language, that's what I stick with.
With the new release of C++ 14, C++ is just getting better constantly.
While Visual Studio don't support it yet, they probably will in next release. Atleast a large chunk of C++ 14.
 
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.
This is a very simple way of learning "how to do everything in an ass-backwards way" - applying things that work in one language to another language does not a good practice make 9 out of 10 times.

EDIT: That's not to say that learning more than one language is a bad idea - it's a very good idea. Thing is, learning legacy crap like Basic is pointless in this day and age as most contemporarily used programming and scripting languages are based on C syntax, so C/C++ is a great starting point - superior to Basic in my opinion.
 
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!
In university last year they teached us c++. One of the assignements was a terminal based labyrinth game based on a main bidimensional array (the map, randomly generated at the start of the program with a dig funcion where # are the outer walls, @ the inner walls and empty spaces where you would move), a secondary 3x3 bidimensional array (what you see). The player was represented by a P in the array. Inputs were wasd as text. I'd suggest to you something like that
 
This is a very simple way of learning "how to do everything in an ass-backwards way" - applying things that work in one language to another language does not a good practice make 9 out of 10 times.
Yes, so you would not write setter/getters in C++ when you just can return reference. And reference in Java is more like a pointer in C++.
 
I forgot to add: Use a good IDE that can provide syntaxing info, error/warning highlighting, code highlighting, code completion, auto-indenting, etc. to make it easier to produce neater, less-error-proned code.
 
... and cracker just kicked off the IDE vs text editor thing.

When in Rome though

I am never quite sure where I stand with IDE vs the rest debate. I am certainly not with the "go vi or go home" crowd, equally not everything has to run a full batch of automated regression tests for every line I change (you can also take that as a condemnation of that test driven programming fad).
The closest I will get is "Good programmers make good code, bad programmers make bad code. An IDE helps mask the bad programmer and may help the good one, however for the former you tend to see the coding equivalent of ode to the the spelling chequer." and I am not sure that is a bad thing. For all that my style of engineering things owes to the bodge it and scarper path I do still appreciate mastery and will tend to find it is those that want to make good code are those that do.

Not I am a great example to follow but I love me some codeblocks, Microsoft do make good programming tools (even if they annoy me at times) but my impatience at the few seconds of load time they have also sees me deal with basic syntax highlighting of notepad++/geany often enough. Fortunately I have been spared Xcode and Eclipse thus far in life.
 
Doing projects is a great way to learn. You will find along the way that there are things you don't know how to do that you must figure out in order to reach your ultimate goal. You can probably find some lesson plans online that will include programming assignments that are designed to make you learn different concepts, so I'd look into that.

Now jumping on the IDE vs. text editor discussion, personally, I use both. Normally, when I'm doing a big project, I tend to go into an IDE as it's nice and organized and looks pretty; also I like the simplicity of debugging within the IDE; I barely remember any of what I did with GDB running from the terminal when I had to deal with a decompiled binary. However when I'm throwing together something simple or maybe tweaking a thing or two, I'll often just use a text editor and maybe write my own makefile. I'll typically use Gedit as my text editor as it does nice color-coding of key words and such for various programming languages.
 
This is a very simple way of learning "how to do everything in an ass-backwards way" - applying things that work in one language to another language does not a good practice make 9 out of 10 times.
This is sort of true, but also not. Like I said in my first post, there are a lot of things that are language specific, and you need to learn the dao of the language you are using (there is nothing worse than Java style python, or C style C++). On the other hand, there are a lot of concepts that are widely applicable (I listed variables, indirection, data structures, iteration, recursion, algorithms, closures, and functional programming in my original post just to name a few), so learning a simple language first makes a lot of sense. I also stand by the fact that no matter what, when you are learning to code everything you do will be wrong (weather on your own or in school), so it doesn't really matter if you fall into the using one languages paradigms in another trap, it will be no more wrong than everything else.

I forgot to add: Use a good IDE that can provide syntaxing info, error/warning highlighting, code highlighting, code completion, auto-indenting, etc. to make it easier to produce neater, less-error-proned code.
NO DON'T DO THIS. IT'S A TRAP. Learning with an IDE might sound like a good idea, but it is horrible. They are a crutch that only help to prevent you from fully learning what you are doing. Feel free to use an editor with syntax highlighting, not having syntax highlighting is insane. I recommend vi, emacs, gedit, or notepad++ (if you are coding on windows for whatever reason). Actually, even professionally, most non-windows devs don't use a real IDE (except for Java; for Java dev a lot of people use IntelliJ).
 
This is sort of true, but also not. Like I said in my first post, there are a lot of things that are language specific, and you need to learn the dao of the language you are using (there is nothing worse than Java style python, or C style C++). On the other hand, there are a lot of concepts that are widely applicable (I listed variables, indirection, data structures, iteration, recursion, algorithms, closures, and functional programming in my original post just to name a few), so learning a simple language first makes a lot of sense. I also stand by the fact that no matter what, when you are learning to code everything you do will be wrong (weather on your own or in school), so it doesn't really matter if you fall into the using one languages paradigms in another trap, it will be no more wrong than everything else.
I bolded things that you should be familiar with anyways because they have more to do with maths than with programming. Data structures work completely differently with every single programming language, so you might as well say that getting familiar with shopping baskets will also help develop knowledge about data structures. As for "functional programming", well gee whiz - of course, except again, the differences between languages are night and day and can cause mass confusion if you start off with a deadbeat language that's far removed from anything that's done contemporarily.

The tl;dr version of what I'm trying to say is that if you start with C/C++, you will have a head start in:
  • Java
  • JavaScript
  • Objective-C
  • C#
  • PHP
  • Perl
Wheras if you start with BASIC, you will have a head start with... BASIC.
NO DON'T DO THIS. IT'S A TRAP. Learning with an IDE might sound like a good idea, but it is horrible. They are a crutch that only help to prevent you from fully learning what you are doing. Feel free to use an editor with syntax highlighting, not having syntax highlighting is insane. I recommend vi, emacs, gedit, or notepad++ (if you are coding on windows for whatever reason). Actually, even professionally, most non-windows devs don't use a real IDE (except for Java; for Java dev a lot of people use IntelliJ).
While I agree that they're a crutch, they're a crutch that actively helps you organize code and learn proper coding habits such as "correct and easily readable" bracketing. On top of that, an IDE like Visual C++ allows you to organize all your resources in one window instead of shuffling with numerous source files, header files and whatever else you choose to include in the project.
Besides, BASIC is an acceptable cruch, but a visual IDE isn't? Double-standards, much? :P
 
An IDE helps mask the bad programmer - I can't say I know of any IDE which does this. If you know one IDE which does, please enlighten me. I have tried Eclipse, Visual Studio with Visual Assist X & resharper. I've looked at my big bro coding in xcode and it seems to have alot of very nice helping things, but it still won't make my big bro code "better" code.

An IDE doesn't identify bad code, it only identifies broken code (some IDEs warn about objects which will be causing memory leaks or problems etc). IDEs haven't come so far in development to actually help mold "bad" code into reusable, fast, easily understandable, small code (which would be the definition of good code).
 
I bolded things that you should be familiar with anyways because they have more to do with maths than with programming. Data structures work completely differently with every single programming language, so you might as well say that getting familiar with shopping baskets will also help develop knowledge about data structures. As for "functional programming", well gee whiz - of course, except again, the differences between languages are night and day and can cause mass confusion if you start off with a deadbeat language that's far removed from anything that's done contemporarily.

The tl;dr version of what I'm trying to say is that if you start with C/C++, you will have a head start in:
  • Java
  • JavaScript
  • Objective-C
  • C#
  • PHP
  • Perl
Wheras if you start with BASIC, you will have a head start with... BASIC.
While I agree that they're a crutch, they're a crutch that actively helps you organize code and learn proper coding habits such as "correct and easily readable" bracketing. On top of that, an IDE like Visual C++ allows you to organize all your resources in one window instead of shuffling with numerous source files, header files and whatever else you choose to include in the project. Besides, BASIC is an acceptable cruch, but a visual IDE isn't? Double-standards, much? :P
Just to be clear, I never recommended BASIC. I think BASIC is a horrible language. I recommended Python (which is heavily used in community projects, academia, and industry), or Scheme (as it has no syntax overhead, and it is a purely functional language (haha parens matching it is like I'm writing LISP (Scheme is a dialect of LISP))).
Many data structures are very similar across languages, from simply things such as strings, arrays or iterators, to more complex structures such as ordered maps, hash maps, red-black trees, array lists, linked lists, etc.
Do you know the definition of functional programming? I don't me "programming that functions" or "programs with functions", I mean the paradigm. I could have also listed imperative and object-oriented, but I feel like functional is the most frequently overlooked (especially in C++ where it is incredibly useful).
Closures are not a mathematical concept. A closure in the group theory sense is very different than a closure under the programming sense.
The concept of learning a language to learn other languages based on it is horrible. C++ is heavily based on C, yet the most frequent way people make horrible C++ code is writing C style C++. Furthermore, based on this logic we should all start by learning FORTRAN (graph explaining why), which would be dumb.
I think that there are arguments to be on both sides of the IDE debate, but those you provided are invalid. You can organize all your resources into one window (or even better terminal) with any of the editors I listed. I also accidentally left sublime text out of my list which is a fantastic editor. My argument was not to use a bad editor, but to avoid code completion (which isn't the end of the world), and snippets (which leads to massively copy-pastaed code, AKA the worst thing ever). Things like being able to open multiple files, syntax highlighting, and bracket matching are a must for any decent editor, and I wouldn't dream of coding without at least that feature set.
 
Personally I would go with C#, especially if you're interested in coding Windows apps. If you want to make Android apps, go with Java, for iOS (iPhone iPad etc), Objective-C. For websites, HTML+CSS+Javascript.
 
On the IDE masking bad programmers bit, I suppose we have to define what bad programmer might be in this case.

That probably goes into programming errors territory, my favourite definitions of those probably comes from the learn ? the hard way (in this case python, though it seems to have gone paid an changed quite a bit so can not seem to find it right now, it was broadly similar to http://msdn.microsoft.com/en-us/library/s9ek7a19(v=vs.90).aspx though). They split it between syntax, wrong functions/libraries and actual fundamental errors in the underlying logic/maths used by the programmer.

A lot of bad programmers that I have seen seem to have the idea of debugging mean "add more close brackets/divs/function close for the given language punctuation" (let us not even go into the force return 0 crowd). Function suggestions, especially with badly named variables, are quite dangerous things and automated tests still do not save you from bad tests.

I can not wait for the day when programming is basically the same as normal language and programmer not such a useful term. For that right now IDEs right now feel like what machine translation is to a universal translator.
 
Hi!
So, yesterday i began working on my text game, but i got into a problem very quickly.
Basically what happens is, i got 2 options, and no matter what option i choose, it'll always go to option 1.
The else function doesn't work either.
Also, after making a choice, it display's text very fast and then closes the window.
Here's the code:
Code:
//Fantasia v0.1 Alpha
//Made by Boy12
 
#include "stdafx.h"
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
 
{
 
    int Choice;
 
    //Chapter 1
    cout << "Fantasia v0.1 Alpha \n";
    cout << "Made by Boy12 \n \n";
    cout << "You wake up in the middle of the night, hearing a knock on the front door downstairs \n";
    cout << "What will you do? \n \n";
    cout << "[1] Go downstairs, and check who is disturbing you in your sleep \n";
    cout << "[2] Keep sleeping, pretending nobody was there, knocking at your front door \n";
    cin >> Choice;
    if (Choice = 1)
    {
        cout << "After opening the front door, you see a old man \n";
        cin.get();
        return 0;
    }
    else if (Choice = 2)
    {
        cout << "You fall asleep again, and nothing unusual ever happened after that night \n";
        cout << "You got the bad ending!";
        cout << "Press a random key, and press enter to exit this program";
        cin.get();
        return 0;
    }
    else
    {
        cout << "Please, choose option 1 or 2";
        cout << "Press a random key, and press enter to exit this program";
        cin.get();
        return 0;
    }
 
}
 
basic text-based game is easy mode. you don't even need to get into the pointer hell in order to do that.
Simply cin and cout and if/switch statements will get you what you want.
So yes I have to say that making a text based game is perfect.
Depending on how advanced you want it ofcourse :)

I myself started with basic
then went to turbo pascal
then to c
then to php
then to c++
then to c#
then to asp.net

C# is my personal preference thanks to all the ease & help you get when writing your code. But since C++ is the most common language, that's what I stick with.
With the new release of C++ 14, C++ is just getting better constantly.
While Visual Studio don't support it yet, they probably will in next release. Atleast a large chunk of C++ 14.


well in mi case it was backwards:

.net

php

c

assembly

mindfuck
 
Hi!
So, yesterday i began working on my text game, but i got into a problem very quickly.
Basically what happens is, i got 2 options, and no matter what option i choose, it'll always go to option 1.
The else function doesn't work either.
Also, after making a choice, it display's text very fast and then closes the window.
Here's the code:
Code:
    if (Choice = 1)
 
    else if (Choice = 2)


There are your errors... two equal signs is what you want :)

EDIT: Some explanations:
if(Choice = 1) is code for the following text:
"If the following statement returns a true value: the variable Choice is successfully assigned the value 1"
Compare this to:
if(Choice == 1):
"If the following statement returns a true value: the variable Choice has the value 1"

In the first (the ones you posted) you assign the value 1 inside the if-statement instead of checking if the value is 1. Therefore it will ALWAYS be true for that first if-statement, and will skip the "else".

This can be useful for more advanced stuff sometimes, if there's a problem assigning a value to something it will return false. But when just using normal variables and values, it will always return true.

EDIT2:

Also, you might want to check out while-loops, so that if the user don't press 1 or 2, you get sent back.
Code:
//quick and easy to understand code, could be written a little more clean
bool user_is_stupid = true;
while(user_is_stupid) //while the statement is true
{
   cout << "write 1 or 2" << endl;
   cin >> value;
   if(value == 1)
   {
      //do something
      user_is_stupid = false;
   }
   else if(vaule == 2)
   {
      //do something else
      user_is_stupid = false;
   }
   else
   {
      cout << "You're stupid! I said 1 or 2!"<<endl;
   }
}

And then there's another way to wait for a random key press than cin.get(); ... but I don't remember it at the moment
 
  • Like
Reactions: Boy12

Site & Scene News

Popular threads in this forum