Friday, October 12, 2012

Teaching Ruby to a 9-Year-Old, Part 2: The Smart - Dumb Computer

This is part of a series of posts titled "Teaching Ruby to a 9-Year-Old."  See the Introduction for more information.


Computers are Really Smart...

Computers are basically giant calculators.  Type in a big multiplication problem, and watch how long it takes to figure out the answer.  Note:  On computers, we say "times" with a *.


This took less than 1 second.  My computer is super smart!


Computers are Also Really Stupid and Stuck Up.

Computers speak their own special language.  If you say something to the computer, and you don't say it exactly the right way, it says it doesn't understand.  Then it barfs on you. Look at these examples when I try to tell it to clear the screen:




Don't Make the Computer Barf

When we write a computer program, we need to be sure we don't make the computer sick.  This means we have to be very careful about how we write things.  Even something as simple as forgetting to put the period at the end of a sentence can make the entire program not work.

 

Nil


A long time ago, I put Ruby on my tablet.  I thought it was broken because it kept saying nil all the time.  Later on, I learned that nil is good!

The word "nil" means "nothing."  When Ruby tells you "nil," it means "Nothing is wrong.  I'm not going to barf on you."  So whenever you see that word on your screen, get excited because the computer just gave you a high-five (or fist bump)!