# Teaching Your Kids to Program: Variables & Data Types

So, we’ve touched on the “grammar” of programming languages, and we’ve dug a little into how programs are structured, so let’s go a little deeper into how programs handle data. If you’re totally new to programming, the terms “variables” and “data structures” might seem like an evocation of some sort of physical embodiment of information. Technically, you wouldn’t be too far from the truth.

A word of warning before we continue: If you’re introducing your children to the basic concepts of programming, this lesson might be a little difficult for them to understand, as it requires a way of thinking about information that can be somewhat counter-intuitive. Remember that repetition is the heart of learning.

At the core of it, variables and data structures are basically like templates for holding specific pieces of information in your computer’s memory. This data can be numbers, letters, sentences or even programming instructions. It’s a broad category, and an attempt at writing an exhaustive list of possible types of data structures would be futile. This point is, think of them as scaffolds, or specifically shaped containers, to hold the data in your program.

We’ll start by looking at variables, which are the more primitive data containers. (We’ll go into detail on data structures in a later article.) Generally speaking, a variable holds a single value. It’s pretty basic on the surface. Think of your computer’s memory as a rack of post office boxes, and the variable names as the addresses to those boxes. Each P.O. box holds a single piece of information, and the variable allows you to access and manipulate it.

The harder concept to grasp is that of data types. This is where the counter-intuitive part comes in. After all, a number is a number, right? What’s the difference between 1 and 1.0? There isn’t, mathematically, but unfortunately, that’s not how computers think. For a computer, the value 1 and 1.0 would require different amounts of memory, since one is more precise than the other, and so trying to give your computer 1.0 when it’s expecting 1, can sometimes cause an error.

For this reason, computer languages have discrete data types that allow you to be totally unambiguous with the information you’re working with. The most common basic types are integer, floating point, boolean, character and string. Integers are whole numbers, like our “1” example above. Integer variables do not have the precision to store fractional values, so if you tried to assign the value 1.2 to an integer type variable, you’d lose all of the data after the decimal.

Floating points are rational numbers, and unlike their simpler integer cousins, can store fractional values. So, assigning 1.2 to a variable with a floating point type will not cause any loss of data.

Booleans are logical values, which can only be true or false. This is often represented in computer languages as 1 and 0 respectively. Booleans can be used like light switches to turn on and off conditions within a program.

Characters are single alpha-numeric values, such as “a” or “-”. The thing to keep in mind is that, as with anything stored in a computer’s memory, characters are actually numbers that represent the symbols humans use. For example, 65 represents “A” on the standard ASCII (American Standard Code for Information Interchange) table, while 109 represents “m”. You can generally just think of characters as being their human friendly equivalents, though.

Finally, we have strings, which are on the border between simple variables and more complex data structures. String variables hold chains of characters, much like the document you are reading right now. Strings can hold small words or large blocks of text, and are actually very similar to a data structure known as an array, which we’ll discuss later.

Developing a firm grasp on the differences between and uses of data types is fundamental to learning to program, and you and your children can build this understanding by focusing on something they’ll need to understand for grade school math anyway: number types. You’ll want to get them to understand that numbers can be organized into groups based on certain properties. The goal should be to teach them to recognize the difference between one type of number and another, or to correctly classify numbers.

You can do this easily using index cards and a marker. Simply write a single value on each card, being sure to mix up the types, and then shuffle the cards. Have your kids sort the cards into their respective types. You can start simply, by just having two types, like integers and floating points, and then increase the complexity by adding additional types, like booleans, characters and strings.

For a more mathematical approach, you can work with real number sets, like natural numbers, whole numbers, integers, rational numbers and even irrational numbers. A classic way to train how to spot these numbers, and the relationships between them, is to write down a series of numbers and ask your children to circle all the numbers of a certain type.

For example, if you write the set {1, 1.2, 0, -5, ⅗}, and ask for all the natural numbers, your children should only circle 1. If you ask for all the whole numbers, they should circle 0 and 1. If you ask for all of the integers, you should get -5, 0, and 1. You get the idea.

Such exercises will help them not only do well in math class, but will set the stage for them to one day build their own army of automatons. Isn’t that what we all desire?