Books & Tools Techniques

Comprehensive coverage of Ruby 1.8 and 1.9

"The New Most Important Ruby Book"
Peter Cooper,
rubyinside.com

Completely updated for Ajax and Web 2.0

"A must-have reference"
Brendan Eich,
creator of JavaScript

Jude

Jude is my Java documentation browser. It combines Sun's definitive javadocs with the easy-to-use format of Java in a Nutshell, and tops it off with easy keyboard-based navigation and full-text searching.

Jude is available for free evaluation.

See the user's guide for more info

Java in a Nutshell

The 5th edition is now out, with complete coverage of Java 5.0!

It includes a fast-paced tutorial on the language, and a compact quick-reference for the core Java API.

Java Examples in a Nutshell

The 3rd edition, updated for Java 1.4

This edition has all-new coverage of the NIO and JavaSound APIs, completely rewritten Servlets and XML chapters, and coverage of new Java 1.4 features (assertions, logging, preferences, SSL, etc.) added througout. A great book for those who like to learn by example. 193 working examples: 21,900 lines of carefully commented code to learn from.

Java 1.5 Tiger: A Developer's Notebook

Amazon incorrectly credits me as the main author on this book. I'm actually the second author: really more of a consultant. This is a good book about all the language changes in the latest version of Java.

Effective Java

I didn't write this excellent book, but I wish I had.

Author Josh Bloch is probably best known for the collections classes in the java.util package. His experience and wisdom are apparent in this book. I learned from it and recommend it highly.

March 29, 2007

More on IE and window.event

Julien Royer sent me an email today following up on this post. Try the following code in IE:

<script>
window.onload = function() {
  alert(window.event == window.event)
}
</script>

When I run this in IE6 on a Windows XP machine, I get false. This is just weird. The window.event object thinks that it is not equal to itself.

This probably does not have any impact on real-world code. I bring it up, however, because in that last post about IE and events, my commenters and I decided that the event object passed to an event handler registered with attachEvent is not the same as window.event. The code shown here calls that into question. Perhaps they are the same objects, but the weird behavior of window.event causes them to appear unequal.

March 26, 2007

Ruby exception-handling quiz

Test your knowledge of Ruby's rescue/else/ensure exception handling construct! Fire up irb to check your answers.

1) What is the value of x?

x = begin 1; rescue 2; else 3;  ensure 4; end

2. What does this method return?

def test
  return 1
rescue
  return 2
else
  return 3
end

3. What does this method return?

def test
  return 1
ensure
  return 2
end

4. How about this one?

def test
  1
ensure
  2
end

5. What kind of exception does this method raise?

def test
  raise ArgumentError
rescue ArgumentError
  raise TypeError
end

6. What kind of exception does this method raise?

def test
  raise ArgumentError
ensure
  raise TypeError
end

7. What does this method do?

def test
  3.times do |x|
    begin
      puts x
      raise "error"
    ensure
      next
    end
  end
end

March 23, 2007

rescue clauses on Ruby class and module definitions

I've been studying exceptions in Ruby, and have discovered some syntax that is not documented in the Pickaxe, nor anywhere obvious that I can find with Google.

Everyone knows about rescue clauses with begin/end. And most Ruby programmers probably know that you can use a rescue clause at the end of a method definition. What I was surprised to discover (by reading the parse.y grammar file in the source distribution) is that rescue clauses are also allowed at the end of class and module definitions.

This, for example, is legal Ruby:

class Test
  def t
    1
  end
  raise "foo"
rescue 
  p $!
else
  p "Class Test defined without exceptions"
ensure
  p "Exiting class Test"
end

p Test.new.t

I'm not sure when this would be useful, but it is legal, and it ought to be documented!

March 15, 2007

4 years in Iraq

This is a letter to the editor of my local paper. Feel free to edit and send it to your paper, too!

To The Editor:

Monday, March 19th is the fourth anniversary of the US invasion and occupation of Iraq. We've now fought in Iraq longer than we fought in WWII. The war has cost $410 billion. That's $280 million a day--more than the daily cost of Vietnam, adjusted for inflation. (These costs are over and above ordinary maintenance costs for the military and do not include future costs for the care of wounded veterans nor future interest payments on the borrowed money to pay for the war.) Most tragically, the war has cost the lives of more than 3,200 US soldiers. Over the last year there have been about 2.5 casualties on an average day. Every day this war continues, two or three more soldiers will die, leaving behind their wives and husbands, their mothers and fathers, their daughters and sons.

Iraq is a quagmire worse than Vietnam. In Vietnam, we knew who we were fighting: the Communists. And the Domino Theory, as flawed as it was, told us why we were fighting. In Iraq, we don't know who we're fighting: is it the Sunnis, the Shiites, the Baathists, the "insurgents", Al-Qaeda in Iraq, or some combination of them? And we don't know why we're fighting: are we trying to stop the spread of WMDs, to promote democracy, to prevent a civil war, or just because we don't know how to get out of the hole we've dug?

Please speak out. It is time to end this senseless war!

Update: comments now closed due to comment spam

March 09, 2007

Metaweb and Freebase.com

There is buzz today about Metaweb decloaking and launching Freebase.com. Both Tim O'Reilly and The New York Times are covering it.

It's a bit of a tease, actually, since Freebase.com is in alpha release and you have to put your name on a list for an invitation code. (Like the early days of gmail). But if you do get in, you might be interested in the documentation I wrote for Metaweb: Developing Metaweb-Enabled Web Applications.

The sign-up for the invitation code is in the lower-right corner at Freebase.com

Advertising
About
Store
Search
Google
Web this site
Archives
Syndicate

Powered by
Movable Type