Programming is language. We use language to communicate with our friends. We use programming to communicate with our computers.
A program is nothing more than a set of instructions for the computer to execute. These instructions outline the plan or project, like a blueprint for a house. Without a blueprint, the builders wouldn’t know what the architect wants, just like the computer doesn’t know how to create what you want without a program.
Learning a programming language is a lot like learning any language. First you start with the basic building blocks–the A, B, C’s. Then you start learning how to put those blocks into words, sentences, and eventually commands that will tell your computer what to do.
Why do we need to speak a strange language to communicate with computers?
This book will help you learn the basics of programming, using the Ruby language. The building blocks you learn in this book will help you learn any other programming language.
Each chapter will go into more detail with basics at the beginning and more complicated material at the end. For now, let’s get started with some simple ideas.
Integers, Floats and Strings…and maybe Ice Cream
Before we can understand how to write programs, we need to understand data. Data is simply information that you can input (give), output (get), store or manipulate with a computer. The two fundamental types of data used in almost every programming language are numbers and strings.
Numbers come in two tasty flavors. Integers, which are whole numbers without a decimal point, and floats, numbers that contain a decimal.
For example, these are integers:
1, 7, 0, 13, 2000
And these are floats:
1.2, 3.14, 5.12345, 0.35
Every time you see a whole number like 8 or 19 you will know they are integers, and every time you see a number with a tasty sprinkle, or decimal, they will look like this: 3.4 or 8.1 and you will know they are (root beer) floats.
Simple, right? Ok, let’s keep going.
The second type of data, or information given to a computer, are called strings. What’s a string? “Anything between quotes is a string.” Since that last sentence was inside of quotes, it was technically a string! You probably see strings all the time without even realizing it!
For example, have you ever seen an alert message on your computer saying something like this:
Somewhere inside a program or web application, an engineer wrote the sentence “File does not exist!” and put it in quotes to create a string. When you were alerted with the pop up box, that string was printed to the screen.
Strings are a little bit like backpacks or lunch pails, they are great for storing all the stuff we care about in an easy-to-carry container. Except with a string, the straps are the quotes. We use strings to store words, sentences, and even files. Here are some examples of strings:
"I'm a string!" "And_so_am_I" "9" "This long paragraph is even a string.\nAnd it has these strange \n things that we'll explain later."
9 is such a joker. Did you notice we put the number nine as a string? This is very different than the actual number nine, but we will get to that later.
Now that you know the two most fundamental pieces of data the computer uses (numbers and strings), it’s time to dive a bit deeper into each of these data types. (Click the bottom left link for the next chapter)