learn the hard way Flashcards
Are you sure # is called the pound character?
I call it the octothorpe because that is the only name that no country uses and that works in every country. Every country thinks its name for this one character is both the most important way to do it and the only way it’s done. To me this is simply arrogance and, really, y’all should just chill out and focus on more important things like learning to code.
If # is for comments, then how come # -*- coding: utf-8 -*-works?
Ruby still ignores that as code, but it’s used as a kind of “hack” or workaround for problems with setting and detecting the format of a file. You also find a similar kind of comment for editor settings.
Why does the # in puts “Hi # there.” not get ignored?
The # in that code is inside a string, so it will be put into the string until the ending “ character is hit. These pound characters are just considered characters and aren’t considered comments.
How do I comment out multiple lines?
Put a # in front of each one.
I can’t figure out how to type a # character on my country’s keyboard?
Some countries use the Alt key and combinations of other keys to print characters foreign to their language. You’ll have to look online in a search engine to see how to type it.
Why do I have to read code backward?
It’s a trick to make your brain not attach meaning to each part of the code, and doing that makes you process each piece exactly. This catches errors and is a handy error-checking technique.
Why is the % character a “modulus” and not a “percent”?
Mostly that’s just how the designers chose to use that symbol. In normal writing you are correct to read it as a “percent.” In programming this calculation is typically done with simple division and the / operator. The % modulus is a different operation that just happens to use the % symbol.
How does % work?
Another way to say it is, “X divided by Y with J remaining.” For example, “100 divided by 16 with 4 remaining.” The result of % is the J part, or the remaining part.
What is the order of operations?
In the United States we use an acronym called PEMDAS which stands for Parentheses Exponents Multiplication Division Addition Subtraction. That’s the order Ruby follows as well.
What is the difference between = (single-equal) and == (double-equal)?
The = (single-equal) assigns the value on the right to a variable on the left. The == (double-equal) tests if two things have the same value. You’ll learn about this in Exercise 27.
Can we write x=100 instead of x = 100?
You can, but it’s bad form. You should add space around operators like this so that it’s easier to read.
What do you mean by “read the file backward”?
Very simple. Imagine you have a file with 16 lines of code in it. Start at line 16, and compare it to my file at line 16. Then do it again for 15, and so on until you’ve read the whole file backward.
space_in_a_car = 4.0
Why did you use 4.0 for space_in_a_car?
It is mostly so you can then find out what a floating point number is and ask this question.
Can I make a variable like this: 1 = ‘Zed Shaw’?
No, 1 is not a valid variable name. They need to start with a character, so a1 would work, but 1 will not.
Why does this not make sense to me?
Try making the numbers in this script your measurements. It’s weird, but talking about yourself will make it seem more real. Also, you’re just starting out so it won’t make too much sense. Keep going and more exercises will explain it more.