Monday, October 29, 2007

My Take on the Rockies Ticket Fiasco

Before I mothball all my baseball thoughts until next Spring, I want to state the following completely unsubstantiated assertions and speculative conjectures about the World Series ticket fiasco:
  1. This was a Java application, evidenced by the fact that users were hitting JSPs. Well built Java applications a very scalable, but this one was not.
  2. They experienced a software and not hardware failure. It was a possible to access the site, but making progress was almost impossible.
  3. 8 million hits in 90 minutes is a lot, but can be handled by a well-designed scalable system.
  4. They were probably not the victim of a malicious attack. Hackers usually demand ransoms these days. I did not hear anything about a ransom in the news. Staging a denial of service attack "just for fun" does not ring true and would require substantial resources.
  5. There was no "online queue". When users entered the site, the window claimed that they were given a place in line, and said not to reload, or they'd lose their place in line. I was thinking about how to implement this, and in theory it can be done with session IDs, but would be difficult to implement fairly and correctly. It may not be possible at all, and I know of no online queues like this. Users were better off hitting reload constantly which is what I did in about 20 Safari web browser tabs. I was actually able to make progress but not enough to buy tickets.
  6. Users that were closer to the servers in California with fast Internet had an advantage over users in Colorado. My wife's cousin was able to buy eight tickets without any difficulties from California, and mysteriously also easily surpassed the four ticket limit.
Next time the Rockies make it to the World Series, they ought follow the Red Sox's example and use a lottery system. It is fairer and kinder to fans.

Oh and by the way, congratulations to the Rockies. They didn't win the World Series, but they had a much better year than anyone expected.

Thursday, October 4, 2007

Book Recommendation: Java Generics and Collections

I recently wrote a blog entry about reluctantly accepting Java Generics. If you are planning on genericising your Java code (which is in principle inevitable for all Java programmers as Sun recommends against using raw types, and may not support them in the future), then "Java Generics and Collections" by Maurice Naftalin, and Philip Wadler is the book for you. It is the clearest, most coherent treatise I have read on the subject. Java Generics make a lot more sense after reading this book.

Declarations like

List<? extends XYZ> list = new LinkedList<XYZ>();

and notions like covariance finally make sense. I even find using wildcards useful since they give programmers some indication as to the purpose of the data structure in addition to providing type safety.

The "Get and Put Principle" in section (2.4) is a real gem. To quote Java Generics and Collections:

The Get and Put Principle: use an extends wildcard when you only get values out of a structure, use super wildcard when you only put values into a structure, and don't use a wildcard when you both get and put.

They also give some best practices on dealing with non-generic legacy libraries. This is particularly useful information, as we are probably a long way from seeing Apache project libraries moving to generics.

(I still wonder about the cost benefit ratio adding so much complexity to the language, but let's ignore that for now.)

There are other resources out there for Java Generics, but they tend to be insufficient or a bit rote like Angelika Langer's huge FAQ. I would actually recommend reading Java Generics first, and if you have questions left over, consult the FAQ.

Moreover, there is a section on the Collections Framework interface that reviews the major Java core data structures (Sets, Queues, Lists, and Maps). This type of material is really great to know. Java programmers tend to gravitate 99% to ArrayList and HashMap, but there are a lot of other fine data structures available in the core language that may be more appropriate for your requirements. Java Generics and Collections covers them all.

There are a few obnoxious typos, such as the broken Function Pattern code. This is confirmed in the errata.

Regardless, this is the best programming book I have read since "Java Concurrency in Practice."