Computer scientists have the annoying habit of using common English words to mean something different from their common English meaning. For example, in English, a statement and a comment are pretty much the same thing, but when we are talking about a program, they are very different.
The glossary at the end of each chapter is intended to highlight words and phrases that have special meanings in computer science. When you see familiar words, don’t assume that you know what they mean!
a. In computer jargon, what’s the difference between a statement and a comment?
b. What does it mean to say that a program is portable?
c. In computer jargon, what is an exception?
Before you do anything else, find out how to run a Ruby program in your environment. Send reader to a tutorial?
a. Type in the “Hello, world” program, save the file as
hello.rb, then run it.
b. Add a second
puts statement that outputs a second message after the “Hello, world.” Something witty like, “How are you?” Run the program again.
c. Add a comment line to the program (anywhere). Run the program again. The new comment should not affect the execution of the program.
It is a good idea to commit as many errors as you can think of, so that you see what error messages the interpreter produces. Sometimes Ruby will tell you exactly what is wrong, and all you have to do is fix it. Sometimes, though, it will produce wildly misleading messages. You will develop a sense for when you can trust the interpreter and when you have to figure things out yourself.
a. Remove the opening quotation mark.
b. Remove the closing quotation mark.
c. Remove one of the
d. Instead of
e. Instead of a quotation mark, write an apostrophe.
f. Instead of both quotation marks, write apostrophes (trick exercise).
g. Remove the space between
"Hello, world." (trick exercise).