Guide

Step By Step

🐣 Variables and Objects

What are Objects?

In computer sciences, an Object is data features that belong to a type. Where a type is a general term, an Object is a specific term.

They exist in memory, and can be abstractions of real (or mathematical) objects, as a word document, or can actually be real life objects, as a real car.

What are Variables?

A variable is a representation inside the program for an object. It's just a name for an object inside the program.

Just as an x in maths can take any number as a value, a variable can take any object of his type as a value.

Declaring is constructing

Declaring your variables is constructing an abstract object of a certain type on data.

The computer then saves a space of soft memory to store the value of that variable during the running period of the process.

To know how much memory space it should save, you have to establish the Type.

Scope

Where a name is valid

The scope of a variable is where you can use it.

I used to tell a joke to explain this:

The teacher is explaining a maths problem, and concludes: " So x is equal to 3"

"But, teacher... " a pupil interjects " you said yesterday that x was equal to 2"

The confusion here is that the scope of x is the problem at hand. You can reuse that or any letter in a different context. The key here is context. This is set in the declaration part.

New variables are built before we begin the program. These exist only for the length of the process.

There is also a way to make a variable refer to an object that will live longer than the process. These are the arguments for functions. The variable, the name, will apply for the inner workings of the process, but the object is applied to it's put into the process as an argument, in parentheses.