Top positive review
Ooh. Ow. Ouch. Eek. Argh. ... Aha.
Reviewed in the United States on November 22, 2005
My wife popped this book open after dinner. Big mistake -- we had planned to spend the night watching Firefly on DVD. She read the first puzzle. We went to the blackboard (yes, we're so geeky and our NY apartment's so small that there's a blackboard in the dining nook). Between us, we had half a dozen possible answers about what a three-line program was going to do. We found at least four boundary conditions and were pretty sure about two of them. For the record, the first puzzle she opened to involved the compound XOR assignment statement x^=y^=x^=y. They're not all that bit-fiddly; some of the other puzzles include class and method mazes, integer or double arithmetic oddities, unexpected exception/initialization interactions, string/charset twistiness, etc.
I thought I'd be good at this kind of puzzle. As an academic, I wrote about programming languages. I read Bloch's "Effective Java" book. Twice. I follow its advice religously and make my coworkers read it. I've read most of the source code for String, StringBuffer and the collections framework and I/O streams. I just came off a week-long coding project where I did exclusively bit-level I/O with all the shifts and masks you could ask for. I was wrong. I got about 1/5 of the puzzles right if I give myself partial credit for diagnosing the boundary condition in the question and having the right answer be in my top two or three guesses.
Unless you've written the bit fiddling parts of a JVM implementation, or are the kind of person who can remember minute details of the specification, you'll most likely suffer. And love it. Then you can relate the puzzles at gatherings of geeks and look on with a smug grin as they twist in the wind. These would be perfect interview questions for a sadistic HR person.
Overall, this book's a jaw-dropping, eye-opening, brain-melting overview of the kind of boundary conditions you can run into with very simple constructions. Most of the puzzles seem to involve implicit conversions done by the JVM, some involve 1.5 features, some involve class inheritance, others exceptions. Almost all of the puzzles contain links to the boundary-condition definition in the Java language spec.
I'll do better next time. Really.