Chapter 1 - Starting programming

I have written a simple game engine with teaching basic principles with a low entry barrier in mind.  Its far from perfect, and I'm not sure currently of the "ease of use" aspect in terms of getting it all setup.  But I think someone industrious enough, even with no prior experience, should be able to suss their way through it.

Before delving into setting up a basic program and writing code, I feel its imperative that some basic principles are covered. 

Everyone has different methods of retaining information, but by my human limits I can only recount that which stuck with me.  I remember first understanding the concept of variables in programming by the idea that you were dealing with a container of sorts, a bucket if you will.  It is able to hold something, some form of information.  You can have an empty bucket, or you can have a bucket that contains something, some information perhaps that is of relevance to the goal of your program.

This is your basic core unit in a sense, from which you build your program structure upon.  Later we could discuss how this works in memory, but from a modern programmers point of view, generally you are sheltered from these more 'hard core' concepts relating to hardware.

Luckily a great deal of us in this century, were given even if reluctantly, a fairly sound understanding of mathematics.  Also fortunately mathematics was a template that guided the construction of programming languages, so you are already in a sense a programmer.

To start, take a number x.  This is a statement most English speakers will understand.  Most if not all programmers would understand the following piece of valid code.

var x;

This is like an empty bucket, with x written on it.  Put something in the bucket?

var x = 1;

You can also do some simple maths in the same line of code, a bit like using a calculator.

var x = 1 + 1;

Or you can add the number later and it will do exactly the same thing but in two lines.  This might seem worse, but actually there can be times where it may be a little clearer!

var x = 1;
x = x + 1;

This code is JavaScript, which although a limited language in some respects, is very easy to use.  Therefore, at least in my opinion (I am fairly new to the language myself at this point), would consider an excellent starting point for an aspiring developer.  I hope that so far these code snippets have been fairly clear for you to understand mathematically, but if they got bigger it would be nice to know what the value is.  I think most programmers actually are not that fond of mental maths, hence why they use a computer, little more than a fancy calculator, to do it for them.

In order to know that the value of the variable, x, is, we shall use another line of code.  This line will print the value to what is called a console.  This is essentially just an output, and you can use it to log what is going on in the program in order to evaluate if your logic is correct.  This of often referred to as 'debugging'.  

In JavaScript, it is quite easy.  The following shows code, and what is printed to the console.

var x = 1;
x = x + 2;
x = x - 1;
console.log(x);

::::console::::-> 2

If you follow it through line by line you hopefully came to the same answer.  Actually most programs start out as something about as simple as this.  And you can imagine a few lines like this would take little time to write.  From here on in you can assume all code is JavaScript, and the term code will likely refer to code written in JavaScript.

It's worth mentioning now of course you can also multiply and divide, and these symbols are * and / respectively.  So to print five multiplied by two in code, you could write:-

var x = 5 * 2;
console.log(x);

::::console::::-> 10

Or you could make it a single line, and for variety we will use the divide operator, the right slash symbol (/).

console.log(10 / 2);

::::console::::-> 5

As you can see programming languages are a combination of mathematics and English (often American English,  :groan:). This is all that is needed to start writing some basic programs.  Next we will introduce variables that contain text types, referred to as 'strings'.  We can then dive into getting a programming environment setup, that is capable of showing graphics on screen, before quickly moving on to making some simple games.

If your curious to get started with the code, here is a link to the repository we will use.

https://github.com/Owlzy/SSPIGE

Comments