corky said:
I have been reading Thinking in Java for a couple of weeks and
I think Bruce mucked up the clarity of examples with the
"simpletest" library. He has this goofy monitor object in his
examples. Perhaps I will like it later...
You like Eckel criticism? »Alright now, let's go«¹
(1: Quoted from »Ballroom Blitz« by Michael Chapman and Nicky Chinn.)
Recently someone claimed that "Thinking in Java 3",
contained this sentence:
|If you're defining an anonymous inner class and want to use an
|object that's defined outside the anonymous inner class, the
|compiler requires that the argument reference be final, like
|the argument to dest().
Here, Eckel writes:
»object that's defined«.
Objects, however, are not "defined", they are /created/ at
run-time. Names of reference variables are being /declared/
in the source text, not "defined".
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#5920
Then, he continues to write
»argument reference be final«.
This might intend to say that a reference parameter was
declared with "final". "final" is not an attribute of a,
/reference/, but of a variable.
However, this is not about /arguments/ (the reference
arguments do not have to be declared "final" here), but
about /parameters/. The distinction between these two
Java terms seems to be unknown to Eckel.
parameter:
http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.8.7
arguments:
http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.12
He also writes:
»the compiler requires«.
It might be the case that the compiler of Mr. Eckel indeed
requires this, but he should teach a language instead of an
implementation, so it might be preferable to write
"the language specification requires«.
Also, anonymous inner classes are not being /defined/ in
Java, as Eckel writes at the beginning of the quotation, but
they are being /declared/.
Moreover, "anonymous" is an unnecessary restriction, because
the assertion is valid for /all/ inner classes. Someone
learning by this sentence thus needs to learn anew at another
time that this is also valid for non-anonymous inner classes,
or he might believe erroneously for an indetermined amount of
time, that it is only valid for anonymous inner classes.
Is there a way to improve the sentence? One attempt by me:
A parameter to be used within an inner class of its method
needs to be declared »final«.
Even the Java Language Specification itself is easier to
read than Eckel (and of course, much more correct):
Any local variable, formal method parameter or exception
handler parameter used but not declared in an inner class
must be declared final.
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3
All the reported faults have been found by me within a single
sentence chosen at random (I did not read the book, but
discovered the sentence in another posting, claiming to quote
this sentence from "Thinking in Java".) If one extrapolates this
error quotient to the whole TIJ, it gives a horrid impression.
Some books might sell chiefly because the buyer wants to
express agreement with their title. When one is learning a
foreign language one does not want to think everything in
English first and then painfully translate it word-by-word.
So one might choose "Thinking in Java" instead of a
garden-variety "Introduction to Java", because one longs for
the promise given by its title, not suspecting that the author
Eckel himself might be far from "thinking in Java".