Learn To Code With Variables

If you could give each of your memories a name, it would make each of them more memorable. Giving a name to everything is human nature. It is how we acknowledge and recognize the presence of something or someone. It is how we remember. It is how we communicate. It is how we share.

When is your birthday? Where do you live? What is your favorite color? Birthday. Address. Favorite color. In programming, the name you give to refer to a specific piece of information is what programmers call a "variable". It's a name to represent a memory. Wikipedia's disambiguation page for the term "variable" as used in computer science defines it as follows:
... a symbolic name associated with a value and whose associated value may be changed.
Of course, the article itself expands on the variable more eloquently. However, the definition above summarizes the variable concisely.

There are memories that can never change (you were born on Earth), and there are memories that can be replaced (Pluto, which was a planet, is now a dwarf planet). Similarly, variables can be constant/read-only (like your birthday) or, literally, variable (like your age, which changes every year, regardless if you stopped counting).

When we think about our own memories, we naturally categorize them somehow. There are memories about people and things. There are memories about places and times. There are good and bad memories. There are happy and sad memories. Similarly, variables can have types. It can be a number, a text or a date, for example. It can be an object or a list. It can be a formula, a condition or a state. It can be clear or cryptic. It can be anything! The variable's type can even be variable/dynamic, assuming the type/types of the value/values assigned to it.

There are memories for family. There are memories for friends and for enemies. There are memories for sharing. There are memories for keeps. Similarly, variables have scope. A variable can be global and available everywhere. A variable can be local and known only by its "owner/owners". Respecting and understanding a variable's visibility is as important as it is for us to respect and understand where and how our own memories are kept and can be used.

Variables allow you to use the computer's ability to remember... or at least to temporarily remember something. It allows you to tell the computer how to simulate your thought process. Given a is equal to b, and if b is equal to c, then c is equal to a. Unless you acknowledge and recognize a, there is almost no way to equate c to anything other than to b. Consider, if you count ten apples from 1 to 10, and you don't remember that you started from 1, you might never be able to convince even yourself that you actually counted ten apples.

Variables are great ways to start your program. If you define a variable, you'd want to value it. Thus, instead of a single line print("Hello World!"), you can instead have two lines of codes starting with string message = "Hello World!", followed by print(message). If it's your first time to code, that actually feels more satisfying.

Comments