When i first learned, i got turned off by java, and jumped right into c/c++ and i've never regretted it. C++ teaches you restraint and shear willpower. You can jump right into c/c++ but as far as it not being an ideal teaching language, im gonna call bull. Why? because you dont have to use anything other than references to objects to program. No one is forcing anyone to use a pointer, and on another note arrays are practically equivalent to a list of references to objects, aka, a pointer to a list. Thats something you probrably wouldn't think about if you have never learned such a language.
If you go into c++, c, java, python or any general programming language learn the following (in order), skipping around take up a lot of time:
0. Basic arithmetic and algebra
1. Basic, trivial computer science: whats a bit? whats a word? whats a byte? how are these stored? what is ram? what is a file? how are characters represented in a computer system? what is syntax and semantics? what is the difference between the two?
2. How to setup a compiler and use an IDE = {Codeblocks, Visual Studio, Netbeans}
3. The 2 standard entry points for any c/c++ application: int main(){return 0;},
int main(int,char*[]){}
4. The different types bool (boolean),char, short, int, long, float, double
5. The difference between floating point numbers and integers (precision and accuracy).
Examples are int vs float or long vs double
6. learn what an operation is. An operation requires operands or variable or constant in which we receive an output, in short operators are just functions.
take the + operator for example
let f(x,y) = what the plus operator returns = f(x,y) = x + y
How about the equals '=' operator? It just assigns the right val to the left value.
7. How to declare a variable, "what is a variable anyway"? It goes back to basic algebra/maths
8. How to get input and do output (cout<<, cin>>, printf(), scanf())
9. Learn simple control structures. if and switch for example. If maps a condition to an execution statement, a statement which you will perform operations within based upon the truth value of the condition "input". switch() on the other hand maps its input a variable for example to a value that matches its value.
10. Make some simple programs to test your knowledge, maybe a simple console based game or guessing game, you know enough now to do something trivial but landmarks your ability to program in general. Make non memory based calculator program that switch's or if's to what operation you want to perform.
11. Truth tables: some may argue that this should be learned earlier but i disagree, the purpose of the other things are to get your hands dirty and appetite wet. I suggest you wikipedia truth tables if you are interested.
12. Learn about loops: What is a loop? It is simply a program statement that is executed over and over based upon the truth value of its input. Take the while loop for example, it is akin to a repeating if statement based upon its truth value.
will these statements ever terminate?:
1 2 3 4 5 6 7 8
|
int main()
{
while( true )
{
//do something here...
}
return 0;
}
| |
1 2 3 4 5 6 7 8 9
|
int main()
{
bool bQuit = false;
do
{
std::cout<<"Hello World"<<endl;
}while(!bQuit)
return 0;
}
| |
13. Congratulations, you have graduated to a level of basic knowedge of the features of most scripting and or programming languages.
14. This ties into math knowledge, What is a function, How do you declare a function? How do you call a function? What does the function return? Is it a method, something that does an doesnt return or does it have a return value?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <math.h>
#include <iostream>
#include <stdio.h>
using namespace std;
//return_type function_name_foo(){} <---in general
float foo_Something(float x, float y,float theta)
{
return x * cosf(theta) - y * sinf(theta);
}
int main()
{
float theta = 45.0f;
float theta_angle_rad = theta * M_PI /180;//degree to radians because 2PI = 360 <=> PI = 180
return foo_Something(0,1, theta_angle_rad);
}
| |
15. Learn about what a pointer and reference is BEFORE you learn about arrays. A pointer is what it says. It points to an address, therefore it is the address, you are able to dereference it to access the object, the object of that memory "address".
none allocation based:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int i_variable = 0;
int* p = &i_variable;
*p = 10; //if *p == 10 then i_variable must be 10 because p points to i_variable
//no cleanup, we didnt allocate anything ourselves, the compiler did it for us
printf("%d\n",p);//is what this prints a value or an address?
printf("%d\n",*p);//again...
return *p;
}
| |
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int iVariable = -1000;
int & r_iVariable = iVariable;
if( r_iVariable == -1000 )//if p then q
printf("Successful reference is successful: %d.\n",r_iVariable);
return iVariable;
}
| |
allocation based (new, malloc, delete, free):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <stdio.h>
using namespace std;//namespaces are for another tutorial, use them, they are your friend
//they are like what folders are to your files, but for your project
int main()
{
int* p_iVariable = new int(10);//dynamically allocates a variable and sets it equal to 10
//most common mistake: p_iVariable = 10 //recall that a pointer is an address
//we want to modify the value at the address, not the address itself
*p_iVariable = 9001;//its over....9000
printf("p_iVariable = %d\n",*pIVariable);
//.... do other stuff
delete p_iVariable;//since we only allocated one we use delete( void* )
//if we did instead p_iVariable = new int[100]; then we would use delete []
//...
p_iVariable = 0;//do this especially if you intend to reuse the pointer
return 0;
}
| |
16. Learn about what an array is. Basically an array is a list of elements or objects of a certain type.
1 2 3 4 5
|
//array of c-style character strings
//each element being a pointer to a character string
//strArray[0] => "Goku"
char *strArray[] = {"Goku","Vegeta","Bardock","Frieza","Chewbacca","idontknowthisnameistoodamnlongtocompileanditisrandomansomayonaseandtoast"};
int u_dirty_sombitch [] = {69};//array with only 1 element.
| |
17. Learn Object/Set theory. What is an object, what can you do to/with that object. What does that object encompass/contain? Classes can be abused but they help you to add structure and reuse to your code as well as abstraction, an easier way to look at things.
...im getting a bit lazy here, but you know what i mean. I got carried away, I hope this helps you all. PS. after all of the above, programming in any other language becomes only a matter of syntax and everything else aside from advanced topics, modifiers for example: const, static, inline,etc., is program language specific.