By Developers, For Developers

Historical errata for Learn to Program

PDF PgPaper PgTypeDescriptionFixed onComments
45TYPO

Perhaps there is a superfluous ‘it’ in this phrase at the bottom of the page? “But it’s my fortune teller, and I say it it’s less fortuitous. So there.”

2007-03-26
98OK

When you copy the code samples and paste it in a text editor, all the single-quoted strings have a leading space erroneously inserted that require manually re-editing of them all. For example (from page 98):

require ’ yaml’ # Told you it was easy.
…
filename = ’ RimmerTShirts.txt’

etc.

I didn’t notice this immediately and wondered why Ruby couldn’t find ’ yaml’. :)

It would be nice if you could just copy and paste and didn’t have to manually fix all those. As far as I can tell, it only happens with single-quoted strings, not double-quoted ones. ???

(Otherwise — great book and awesome job you guys are doing.)

(Dave says: PDFs are formatted text—rather than cut and paste from it, you should probably just download the code from the book’s web site)

2006-03-06
128OK

This is nitpicky, but in the 3rd paragraph, the author claims that methods are not objects. However, in Ruby methods are objects, you just have to use some magic to get at them.

More to the point, he suggests that methods cannot be passed to other methods. However, this is untrue as you can use method(:meth_name) to gain access to the method object. This object can then be passed to other methods.

(Dave says: actually, Chris is correct. Methods are not objects. They can, however, be wrapped in objects, which is what method() and unbound_method() do.)

2006-03-06
80TYPO

“5. Then find the largest two, and see whether they look like like fun to play on.”

Superfluous “like”.

Should be:

“5. Then find the largest two, and see whether they look like fun to play on.”

2007-03-26
104OK

not sure whether it’s a pun because the phrase comes in the middle of a ‘string’ explanation but I’m French and therefore I had to point out that the expression is ‘et voilà’ and not the erroneous ‘et viola’.

Great book anyway.

(Chris says: ’tis a pun)

2007-03-26
103ERROR

Hi - not sure of this is an error, exactly. But when I run the Photo renaming utility, I get
‘rename’: Cross-device link - /Volumes/EOS_DIGITAL/DCIM/126CANON/IMG_2650.JPG or Animals01.jpg (Errno::EXDEV)

This is using a USB card reader on a Powerbook G4 on OSX 10.4.6

15OK

Following the instructions to check Ruby version in Command Prompt…

I enter “ruby -v” at the prompt and instead of seeing a variation on:

ruby 1.8.2 (2004-12-25) [i386-mswin32]

I got:

C:\\Documents and Settings\\tb18711>ruby -v
‘ruby’ is not recognized as an internal or external command, operable program or batch file.

The install was successful…I have New > Ruby Program in my contextual menu for folders, and the SciTE is the default app for the Edit option on the .rb contextual menu.

This is a work computer, where you generally have to have admin rights to install new software. Maybe that has something to do with this problem, but it is not mentioned in the tutorial.

(Dave says: Ruby must not be in your path)

2007-03-26
83OK

“This code works fine because the continent does not border the edge of the world. If it did, then when we send our little guys out (that is, call continent_size on a new tile), some of them would fall off the edge of the world (that is, call continent_size with invalid values for x and/or y), which would probably crash on the very first line of the method.”

No error occurs when the ‘continent’ is extended to the ‘edge of the world.’

(Chris says: It doesn’t crash for every value, but it crashes for some. (Put a
land tile on 10, 10, and search from (10, 10).) I don’t know how
specific we need to be about this, though… the point is that there’s
some error checking that I’m not doing relating to the borders of the
world. I didn’t want to fill the example with it, but didn’t want to
let it go without mentioning it. I used “probably” because it doesn’t
crash for every value.)

2007-03-26
12TYPO

2.4 A Few Things to Try
…
…
…, so be as accurate

2007-03-26
37TYPO

Though the code:

puts(rand(101).to_s+’ % chance of rain,’ )

works just fine, it doesn’t match the spacing convention used elsewhere. If some spaces were added, it would fit the pattern:

puts(rand(101).to_s + ’ % chance of rain,’ )

2007-03-26
45OK

In the paragraph:

Branching is kind of like coming to a fork in the code: do we take the
path for people whose name == ‘Chris’, or else do we take the other,
less fortuitous, path? Clearly, branching can get pretty deep. (Well, I
guess you could also call it the path of fame, fortune, and glory. But
it

2007-03-26
38TYPO

In the floating caption in the margin

2007-03-26
86OK

In the continent_size problem, you have transposed your array values. If you try continent_site(world, 1, 4) with your world array, your code fails. Instead of “if world[y][x] != ‘land’” and “world[y][x] = ‘counted land’” you should use “world[x][y]” Note that you have transposed the passed values. [x] is the initial array value and [y] is the inner array value.

(Chris says: In fact, if you use his values (1, 4), you get 0 as
expected. If you use (4, 1), you get 2, as expected. Because of the
way arrays literals are formed and the way arrays are accessed, the
first index is the column value, and the second is the row value.)

2007-03-26
viiTYPO

On first page of Introduction, third paragraph begins “It has been more than decade.” This should read “It has been more than a decade”

12TYPO

In the third bullet-point under “2.4 A Few Things to Try”:
“. . . be as accurate—or not—you want.)”
should read
“. . . be as accurate—or not—as you want.)”

36TYPO

The marginal comment on this page is garbled:
“Modulus, much like
integer division, might
seem bizarre, but they it
is actually really useful,
often when used with
integer division.”

Huh?

1SUGGEST

If anyone’s interested, I put up solutions to the problems in the book, right here: learntoprogramanswers.blogspot.com

38TYPO

The description of the code says “Note that I used rand(101) to get numbers from 0 to 100 and that rand(1) always returns 0.” He’s making a point there about using rand(100) would give you numbers up to 99. However, in the code example he’s referring to, (bottom of the previous page) he actually uses rand(100) in the example he’s referring to … which makes this comment quite funny: “Not understanding the range of possible return values is the biggest mistake I see people make with rand, even professional programmers, and even in finished products you can buy at the store.” Just goes to show that it’s not always a lack of comprehension at fault.

39TYPO

I believe that “Suffice it to say” should be “Suffice to say”.

71SUGGEST

This book is my first foray into any programming language, and I’m finding it extremely readable and helpful. Thank you!

The code example about “tough_var” being defined locally didn’t strike me as meaningful at first… until I played around with the order of the code. The impact of local definition was made clear when I ordered it this way:

—code—
tough_var = ‘You can\\’t even touch my variable!’

def little_pest tough_var
\ttough_var = nil
\tputs ‘HAHA! I ruined your variable!’
\tputs tough_var.to_s
end

little_pest tough_var
puts tough_var
—/code—

This defines the variable shown to be modified before the local method, which to my admittedly inexperienced way of thinking is a bigger deal. Since I had to rearrange the code to get the gist of the lesson, thought you might like to know.

Maybe that shows that by this point in the book, you’ve already equipped me with enough knowledge to be able to figure out through experimentation. :) Thanks again, I’m loving the book.

15ERROR

You have us type:

puts ’ 12’ + ’ 12’

Because of the space after the third quote, the output should read 12 12 but in the book it says 1212. The same error occurs below in the statement:

puts ’ 2’ * 5

64TYPO

reads: “what I want you do to with each”
rather than “what I want you to do with each”

161TYPO

Under “99 Bottles of Beer on the Wall >How you could do it:”

There is no solution. It just says:

#<NameError: undefined local variable or method ‘’ for #

161TYPO

The how you could do it section looks to be pulling some code from somewhere but is erroring out with “#<NameError: undefined local variable or method ‘’ for #”

162TYPO

Under the deaf grandma solution, the “how you could do it” section looks to be pulling some code from somewhere but is erroring out with “#<NameError: undefined local variable or method ‘’ for #”

163TYPO

Under deaf grandma extended - The how you could do it section looks to be pulling some code from somewhere but is erroring out with “#<NameError: undefined local variable or method ‘’ for #”

164TYPO

Under the leap years section - The how you could do it section looks to be pulling some code from somewhere but is erroring out with “#<NameError: undefined local variable or method ‘’ for #”

164TYPO

Under the leap years section - The how you could do it section looks to be pulling some code from somewhere but is erroring out with “#<NameError: undefined local variable or method ‘’ for #”

165TYPO

Under building and sorting an array - The how you could do it section looks to be pulling some code from somewhere but is erroring out with “#<NameError: undefined local variable or method ‘’ for #”

166TYPO

Under table of contents revisited - The how you could do it section looks to be pulling some code from somewhere but is erroring out with “#<NameError: undefined local variable or method ‘’ for #”

36TYPO

There is a side note that reads:

“Modulus, much like
integer division, might
seem bizarre, but they it
is actually really useful,
often when used with
integer division.”

“…but they it…” is a typo, I believe.

Thanks for a great book!

Categories: