The Building Blocks of Every Programming Language (Part 1)

Coding is everywhere in today’s tech-savvy world, but how do computers think?

Since computers are programmed using numbers, one can see many similarities to mathematics within programming languages.

Variables

Like math equations, programming languages also have variables. Programming languages have many different types of variables, though. These include:

a) String (or words) – Examples of this are the infamous “hello world” or any other phrase or sentence that one would like to read like text.

b) Number – There are actually 3 different sub-types within number variables. These include integer, single-precision (or float), and double-precision.

c) Boolean – Booleans can only have two values, 0 or 1. They are more commonly known as true or false. These are best for testing a certain condition.

d) Arrays or lists – These are pretty self-explanatory. They are a list of variables.

e) Classes and Objects (optional) – These are the crux of object-oriented programming, and allow computers to think more like humans. They are out of the scope of this article though.

Operations

Most programming languages come with built-in math ability, such as addition, subtraction, multiplication, and division of numbers. This may not seem like much, until you realize that computers languages have four or five different types of variables. One can add strings, subtract items from lists, and a whole host of other neat tricks.

Conditional Statements

Perhaps one of the most powerful options that programming languages give us is the ability to select which parts of your code execute depending on what conditions are currently true. These are also called if-then statements.

Here we can start combining the concepts that are discussed previously. For example, suppose you wanted to execute one piece of code if a specific whole number is even, and another piece of code if that same variable is odd. How could we do this? Here is the pseudocode logic.

if var == even:

then execute some function

else:

execute another function

Many people say computers teach us how to think, and it’s true because in order to implement this pseudocode, we literally have to go back to how we define “odd” and “even”, and explain to the programming language these definitions in terms of variables it can understand.