The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

jamgard (9) [Avatar] Offline
#201
Re: Errors and Corrections
p. 194 - Listing 7.22

boxer.fightBack = { times -> return this.takeThis * times }

this.takeThis : the use of "this" won't work here. The enclosing lexical scope is the script and not boxer's class.
Removing "this" makes the example work.

The listing doesn't work on 2.2.1 or 1.8.9

Was in first edition, too.
nlwillia (11) [Avatar] Offline
#202
3.5 Quote attribution
“Once a programmer had a problem. He thought he could solve it with a regular expression. Now he had two problems.” — From a fortune cookie

This quote from the beginning of section 3.5 should be attributed to Jamie Zawinski.

http://regex.info/blog/2006-09-15/247
daleqq (1) [Avatar] Offline
#203
Re: Errors and Corrections
p137 first paragraph
"you could legitimately assume this would refer to the current object, which is the closure object itself."

I test it with groovy 2.2 but this is refer to the "Mother" class.
And I find the description within groovy document: "this: as in Java, this refers to the instance of the enclosing class where a Closure is defined"
Mittie (397) [Avatar] Offline
#204
Re: 3.5 Quote attribution
cool. Thanks for the pointer!
danhyun (5) [Avatar] Offline
#205
Re: Errors and Corrections
MEAP v17

Listing 3.4 Working with GStrings

The listing's assertion that

assert out == 'Year 70 Month 0 Day 1'


fails. I am using JDK 7 and Groovy 2.2.1

Assertion failed:


assert out == 'Year 70 Month 0 Day 1'

       |   |

       |   false

       Year 69 Month 11 Day 31


Similarly, any subsequent assertions about
dateMap.y
being 70 also fails.

Message was edited by: danhyun
danhyun
danhyun (5) [Avatar] Offline
#206
Re: Errors and Corrections
MEAP v17 [pdf] end of page 76 to top of page 77

The associated listing shows:

def greeting = 'Hello'


But the text reads:

"You might also note that a greeting was explicitly typed. It’s effectively of type Object and can reference both String and StringBuffer values."

It seems that should read "not explicitly typed" or "implicitly typed"
Terminal Velocity (2) [Avatar] Offline
#207
Re: Errors and Corrections
On page 74 (version 16), the URL http://www.nvcc.edu/home/drodgers/ceu/resources/test_regexp.asp takes the user to a 404 page not found.

I tend to use http://www.regexplanet.com/advanced/java/index.html for all my regex testing
danhyun (5) [Avatar] Offline
#208
Re: Errors and Corrections
MEAP v17 [pdf] end of page 130 - 131

Listing 5.6 firstly declares that fast is more than 5 times faster than slow. On my machine it only runs 4.8 times faster:

Fast is 4.8413370763 times faster than slow
Fast: 40845327
Slow: 197745996

Also the paragraph says that "As a
side effect, we learn that the general number division takes more than 15 times longer than
the optimized intdiv method."

15 is most likely a typo for 5 but this still isnt true on my machine.
Mittie (397) [Avatar] Offline
#209
Re: Errors and Corrections
Hi Danny,

thanks for pointing that out! These numbers were actually the case (no typo) with Groovy versions before the optimizations for arithmetic operations. They make quite a difference smilie
Anyway, we have to rethink that section - maybe even scratch it totally.

Thanks a lot for posting
Dierk
fatbear (4) [Avatar] Offline
#210
Re: Errors and Corrections
Using MEAP v17:

For Listing 19.1 on p. 634, why is the import needed? The enum Direction is already provided in the code. In the paragraph below, remove "In #2, ...." In the third-to-last paragraph on the page, change "All in all, fifteen lines...." to "All in all, thirteen lines...."

P. 634, change the sentence (grammar error):

"A Domain-Specific Language isn't supposed to be concise and readable?"

to:

"Isn't a Domain-Specific Language supposed to be concise and readable?"

P. 635, first paragraph, fix run-on-sentence from "at its own pace, and the same is true..." to "at its own pace. The same is true...."

P. 635, second paragraph, not necessarily a grammar error, but it is odd usage: change "infrastructural code" to "code infrastructure"

P. 635, second paragraph, change: "So compared to" to: "So, compared with" (note "to" implies a different order of things; "with" is used when comparing things of the same order. See http://www.dailywritingtips.com/compared-to-or-compared-with. Also, put a comma after the conjunction "So").
alexwibowo (2) [Avatar] Offline
#211
Re: Errors and Corrections
I'm reading MEAP v17, and this snippet on page 223 confuses me a little bit. I think it has been pointed before, but I'm not sure if it is supposed to have been fixed.


def groovyObjectInvoke(Object obj, String method, Object args){
if (obj instanceof GroovyInterceptable) {
return obj.metaClass.invokeMethod(method, args)
}
if (! obj.metaClass.respondsTo(method, args)) {
return obj.metaClass.invokeMethod(method, args)
}
obj.metaClass.invokeMethod(obj, method, args)
}

Seems like there are 2 versions of 'invokeMethod', one that specifies the 'context', and another that doesnt?

Thanks

Alex
Mittie (397) [Avatar] Offline
#212
Re: Errors and Corrections
Hi Alex,
thanks for your posting.

This snipped marked as // MOP pseudo code
which may be the root of some misunderstandings. It is not real code.

In the first edition I used a Nassi-Shneiderman diagram for a similar purpose but I thought that code would be easier to understand. I may have been wrong in that assumption.

Thanks for you feedback
Dierk
ryacobellis (6) [Avatar] Offline
#213
Re: Errors and Corrections
In Section 2.3.8 of MEAP v17 this final assert fails in GroovyConsole 2.2.2:

assert x.reverse() == 10..1 // assert fails

When I display x in the Console it displays as 1..10, but when I display x.reverse() it displays as [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], a List, not a Range.
ryacobellis (6) [Avatar] Offline
#214
Re: Errors and Corrections
I should have mentioned that I'm using Java 8 on Windows 7 Ultimate, in case that makes a difference.
ryacobellis (6) [Avatar] Offline
#215
Re: Errors and Corrections
In Section 3.5.2 the regex pattern related to "twister must contain only words delimited by single spaces" is not correct (the asserts in lines #A and #B fail).

One possible replacement pattern (too general, but works) is this:

def pat = / ?w+( w+)* ?/

A pattern that does what you want for the type of string you have is this:

def pat2 = /(w+ w+ ?)*/ // the " ?" was added to the end of the group

Alternatively, and somewhat simpler:

def pat3 = /(w+ ?)+/

Message was edited by:
ryacobellis
ryacobellis (6) [Avatar] Offline
#216
Re: Errors and Corrections
This may have been covered by someone else already; if so, please ignore it.

On PDF page 86 of MEAP v17, the line before the "Use whitespace wisely" box says this:

Note the difference in spelling in (#1). This isn’t a =~ b but a= ~b. Tricky.

I think it should say this instead (that is, I think the two parts are reversed):

Note the difference in spelling in (#1). This isn’t a= ~b but a =~ b. Tricky.
ryacobellis (6) [Avatar] Offline
#217
Re: Errors and Corrections
On page 112 of the MEAP v17 PDF, this paragraph appears a little above Listing 4.13:

The value method returns the list of values. Because maps have no idea how their keys are ordered, there’s no foreseeable ordering in the list of values. To make it comparable with our known list of values, we convert both to a set.

I think it should say:

The values method returns the list of values. Because maps have no idea how their keys are ordered, there’s no foreseeable ordering in the list of values. To make it comparable with our known list of values, we convert it to a list before comparing it using List equals.
ryacobellis (6) [Avatar] Offline
#218
Re: Errors and Corrections
The discussion about "this" vs. the "declaring object" == "owner" on pages 137 and 138 of MEAP v17 PDF is confusing to me. If a closure is declared inside a class then "this" and "owner" refer to the same class in GroovyConsole 2.2.2, namely Mother in Listing 5.9.

On page 138 toward the top I think the comment in bold about #4 should say //#4 Mother (declaring object), and I think the discussion 4 paragraphs later about the println at #4 should say:

"At (#4) the example should print the class name that the closure is defined in, namely Mother, by the time you’re reading this. Groovy versions before 1.0 printed the closure type."

Or, perhaps you could replace #4 in Listing 5.9 with the following assert, revise the two-sentence paragraph above, and eliminate footnote 3 on p. 137:

assert context[0] instanceof Mother // #4
farabhi (1) [Avatar] Offline
#219
Re: Errors and Corrections
Range datatype extends List, so when you you use reverse() method on a range it returns a list - this is why you see that in console.
However is shouldn't matter for assert statement, as in this case it deals with equality, not identity, it doesn't check the types as it would do had we use assert x.reverse() instanceof Range.
Maybe, this is Java 8, not sure; it worked fine on both my Java 6 and 7.
jdinkel (4) [Avatar] Offline
#220
Re: Errors and Corrections
Hello Editors,

Same problem for me with IBM-128 link. Can somebody add it to the errata and fix it? Mine is on PDF page 134 not 138 but also from v17. But it is now 2014, not 2013. Maybe there was some regression?

Thanks,
Jason
jem37 (1) [Avatar] Offline
#221
Re: Errors and Corrections
Chapter 1 available 12/1/14 at http://www.manning.com/koenig2/Koenig_MEAP_Ch1.pdf

The output of the code on page 11 doesn't match the data on page 10: It looks like you substituted Tim Cook for Steve Jobs in one, but not the other.
lnorth (6) [Avatar] Offline
#222
Listing 9.38 in v17 Is Missing ReturnStatement Import
Listing 9.38 in v17 is missing:

import org.codehaus.groovy.ast.stmt.ReturnStatement
Mittie (397) [Avatar] Offline
#223
import meanwhile added.

thanks
Dierk
1987 (1) [Avatar] Offline
#224
[a0zA-Z0-9]
for Uppercase or lowercase letter or digit
on page 850
should read
[a-zA-Z0-9]
Mittie (397) [Avatar] Offline
#225
well spotted!

Thanks
Dierk
Neil Winton (1) [Avatar] Offline
#226
I've spotted a few so far in the 23/3/15 version (in the Kindle edition)

Section 3.4.3, just before figure 3.5 the last two sentences starting "In this listing you're using getAt(x)..." seem to have been review comments that have been incorporated.

In section 4.3.1 it states in the 5th paragraph that maps are, by default, of type Java.util.HashMap. they are actually of type Java.util.LinkedHashMap, as it shows in the examples shortly after.

In section 5.3.3 after listing 5.2 the text refers to first.&validate and second.&validate, but the listing uses filter5 and filter6.

Just after figure 5.2 it talks about default parameters for closures and states "the same rules apply as for default parameters for methods." However, default method parameters have not been covered at this point and when they are, in chapter 7 there are no obvious rules defined (but maybe I've missed them).

I'm really glad to see the new version nearly there!

Regards,
Neil
Görge (2) [Avatar] Offline
#227
7.3.4 (GINA2 V18)
3rd paragraph, 2nd sentence: Missing "do" in
Saving has nothing to with books
Görge (2) [Avatar] Offline
#228
Listing 7.18 hardly readable on OS X iBooks (GINA2 V18)
When switching iBooks to to "Two Pages", listing 7.18 is hardly readable. Seems to be a "tab vs. spaces" problem.
Mittie (397) [Avatar] Offline
#229
Thank you!