learn the hard way Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Are you sure # is called the pound character?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If # is for comments, then how come # -*- coding: utf-8 -*-works?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why does the # in puts “Hi # there.” not get ignored?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do I comment out multiple lines?

A

Put a # in front of each one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

I can’t figure out how to type a # character on my country’s keyboard?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why do I have to read code backward?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why is the % character a “modulus” and not a “percent”?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does % work?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the order of operations?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between = (single-equal) and == (double-equal)?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can we write x=100 instead of x = 100?

A

You can, but it’s bad form. You should add space around operators like this so that it’s easier to read.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What do you mean by “read the file backward”?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

space_in_a_car = 4.0

Why did you use 4.0 for space_in_a_car?

A

It is mostly so you can then find out what a floating point number is and ask this question.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can I make a variable like this: 1 = ‘Zed Shaw’?

A

No, 1 is not a valid variable name. They need to start with a character, so a1 would work, but 1 will not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why does this not make sense to me?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

If you thought the joke was funny could you write hilarious = true?

A

Yes, and you’ll learn more about these boolean values in Exercise 27.

17
Q

puts “Its fleece was white as #{‘snow’}.”

`Why are you using the variable named ‘snow’?

A

That’s actually not a variable: it is just a string with the word snowin it. A variable wouldn’t have the single-quotes around it.

18
Q

Is it normal to write an English comment for every line of code like you say to do in Study Drill 1?

A

No, you write comments only to explain difficult to understand code or why you did something. Why is usually much more important, and then you try to write the code so that it explains how something is being done on its own. However, sometimes you have to write such nasty code to solve a problem that it does need a comment on every line. In this case it’s strictly for you to practice translating code to English.

19
Q

Can I use single-quotes or double-quotes to make a string or do they do different things?

A

In Ruby the “ (double-quote) tell Ruby to replace variables it finds with #{}, but the ‘ (single-quote) tells Ruby to leave the string alone and ignore any variables inside it.

20
Q

Should I use %{} or #{} for formatting?

A

You will almost always use #{} to format your strings, but there are times when you want to apply the same format to multiple values. That’s when %{} comes in handy

21
Q

Why do I have to put quotes around “one” but not around true orfalse?

A

Ruby recognizes true and false as keywords representing the concept of true and false. If you put quotes around them then they are turned into strings and won’t work.

22
Q

Why do I get an error when I put spaces between the three double-quotes?

A

You have to type them like “”” and not “ “ “, meaning with nospaces between each one.

23
Q

Is it bad that my errors are always spelling mistakes?

A

Most programming errors in the beginning (and even later) are simple spelling mistakes, typos, or getting simple things out of order.

24
Q

ESCAPE:

\

A

WHAT IT DOES:

Backslash ()

25
Q

ESCAPE:
'

A

WHAT IT DOES: Single-quote (‘)

26
Q

ESCAPE:
"

A

WHAT IT DOES:

Double-quote (“)

27
Q

ESCAPE:\a

A

WHAT IT DOES: ASCII bell (BEL)

28
Q

ESCAPE:
\b

A

WHAT IT DOES:

ASCII backspace (BS)

29
Q

ESCAPE:

\f

A

WHAT IT DOES:

ASCII formfeed (FF)

30
Q

ESCAPE: \n

A

WHAT IT DOES: ASCII linefeed (LF)

31
Q

ESCAPE:

\r

A

WHAT IT DOES:

ASCII Carriage Return (CR)

32
Q
A