Variables! — the building blocks of programming

Dennisse Pagán Dávila
CodeX
Published in
3 min readMar 21, 2021

What are variables?

Variables are labels used to store one or multiple values and data. They are assigned a descriptive name so that the code is more readable to the programmer; this is exceptionally important when working in teams where your code may be accessed by multiple members, in which case, it must be as readable as possible.

Simply put: You can think of them as storage boxes, and the label outside lets you know their contents.

The data can come from a user, such as when a game asks you to select the difficulty.

Final Fantasy VII Remake Difficulty Menu

Data can also be set by the programmer like the Health Points(HP) or lives the player has.

Regardless of the kind of data stored, variables are assigned a name, a value, and a type. The contents may change and vary, hence the name.

Private or public

Variables have a private or public reference. Private variable names conventionally start with an underscore to easily spot them throughout the code and differentiate them from the rest.

Nonspecified variables are always private, which means only the script in question has access to it. A public variable allows for communication with other scrips.

Variables can also be global when placed at the top of our code before any methods but within the script class. Global means that they can communicate with all the methods in the script.

Some of the most common variables include:

Assigning variables

Here we assign a lives variable:

The line above is a statement. Programs are made up of of statements — instructions that tell our systems what to do and how to do it.

Re-assigning variables

The value of a declared variable can change throughout our code. For instance: In the event our player takes damage, the lives variable will decrease accordingly.

Psudocode for variables

Variables tend to be simple and descriptive enough to not stress the programmer on how they are presented in pseudocode conventions, however, there is one. The convention for assigning a value to a variable in pseudocode is done using an arrow that points toward the variable, and the value at the opposite end is what is being stored within it.

A←50

The same as declaring a variable like

However, bear in mind that pseudocode can be written in your own natural language without having to worry about specific ways to represent it. I will be talking more about pseudocode in my next article.

--

--

Dennisse Pagán Dávila
CodeX
Writer for

Software Engineer that specialize in Game Development. Currently looking for new opportunities. Portfolio: dennissepagan.com