Monday, September 11, 2006

Using Annotations to Build Object Representations

One of my co-workers came to me with a familiar problem. He had class that was being rendered as XML. The class itself could have different renderings, so the XML creation was done using a classic builder pattern. This was good, but he still fretted about how his class would probably change (new features, imagine that) and he would have to change the XML builders so they would output the new properties.

It's a classic model-view coupling problem. I had suggested the builder architecture, in part because I remembered a classic article by Holub on this kind of problem. I started thinking and came up with a possible solution. This solution may have its own design flaws, but it was interesting.

My idea was to use Java's annotations to decide what parts of an object need to be present in its representation. Thus the annotation was a clue to the builder saying "show me." A reusable builder could this be built to simply obey the hints provided by the object it was building a representation for. In this case, everything was XML.

So I built a simple annotation class:


import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;

@Documented
@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface XmlView {
XmlViewType value();
}

I created this XmlViewType as an Enum. Basically there could be one value in the Enum for each representation needed. Actually value() should really return an array of XmlViewTypes, since you will often want to show the same data in different representations. Or for maximum reusability, just have it return an array of strings. You can pass in the value to match against later.

Now to create a reusable builder.




import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Type;

import org.apache.commons.lang.StringUtils;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class AnnotationXmlBuilder{

public static Element buildXml(Object obj, XmlViewType type){
String objName = obj.getClass().getSimpleName();
return buildXml(obj, objName, type);
}
public static Element buildXml(Object object, String elementName, XmlViewType type){

if (isPrimitive(object.getClass())){
Element e = DocumentHelper.createElement(elementName);
e.addText(String.valueOf(object));
return e;
} else if (object instanceof Iterable){
Iterable iter = (Iterable) object;
String pluralName = "";
String singularName = "";
if (elementName.endsWith("s")){
pluralName = elementName;
singularName = elementName.substring(0, elementName.length()-1);
} else {
pluralName = elementName + 's';
singularName = elementName;
}
Element e = DocumentHelper.createElement(pluralName);
for (Object obj : iter){
e.add(buildXml(obj, singularName, type));
}
return e;
} else if (object.getClass().isArray()){
String pluralName = "";
String singularName = "";
if (elementName.endsWith("s")){
pluralName = elementName;
singularName = elementName.substring(0, elementName.length()-1);
} else {
pluralName = elementName + 's';
singularName = elementName;
}
Element e = DocumentHelper.createElement(pluralName);
int length = Array.getLength(object);
for (int i=0;i<length;i++){
Object obj = Array.get(object, i);
e.add(buildXml(obj, singularName, type));
}
return e;
} else {
// go through its methods
Element e = DocumentHelper.createElement(elementName);
e.addAttribute("kind", object.getClass().getSimpleName());
for (Method method : object.getClass().getMethods()){
XmlViewType xvt = getAnnotation(method);
boolean showMethod = ((type == null) ||
(xvt != null && xvt.equals(type))) &&
isProperty(method);
if (showMethod){
String propertyName = StringUtils.uncapitalize(method.getName().substring(3));
try {
Object val = method.invoke(object, (Object[])null);
e.add(buildXml(val, propertyName, null));
} catch (Exception exc) {
// eat it for now
}
}
}
return e;
}
}

private static boolean isPrimitive(Type type){
return (type.equals(String.class)) || (type.equals(Integer.class)) || (type.equals(Long.class))
|| (type.equals(Double.class)) || (type.equals(Float.class)) || (type.equals(Byte.class)) ||
(type.equals(Boolean.class)) || (type.equals(Short.class)) || (type.equals(Character.class))
|| (type.equals(Character[].class));
}

private static XmlViewType getAnnotation(Method method){
if (!method.isAnnotationPresent(XmlView.class)){
return null;
}
return method.getAnnotation(XmlView.class).value();
}

private static boolean isProperty(Method method){
return method.getName().startsWith("get") && !method.getName().startsWith("getClass");
}
}

This class returns a dom4j Element, but one could easily switch XML technologies for this. It would not be too hard to do it with just pure DOM. Anyways, what does this code do? It takes in a class and view type. It iterates over all methods in the class, looking for getters. If it finds a getter, then it looks to see if it has been annotated with the XmlView annotation. If so, it compares the value to the value passed into the method. If they match, then it uses the name of the property and invokes the getter. If the return type is a primitive or a String, then it crates a corresponding node for it. If it is a list or array, it creates a surrounding element, then creates a child element for each item in the array or list. If the return type is some other kind of object, then it descends the object graph using recursion. So if your class had a getFirstName method and an instance of this class happened to return "Michael" for this, then you would get something like <FirstName>Michael</FirstName> in your XML. If you object had a getCar() method that returned a Vehicel object, and Vehicle had a getMake() method you might get something like: <car><make>Volkswagen</make></car> Pretty straightforward.


Vista in the End

I read this interesting article about Windows Vista. Vista may well be more significant than the author realizes. It may well be the greatest piece of shrink wrapped software ever produced, and perhaps the final hurrah for shrink wrapped software.

For years people have talked about moving applications online. Proponents of on-demand applications tried to argue that they would win out for a variety of reasons, such as portability, ease of maintenance, lower cost, etc. The truth is that maybe they will win out just because it will become too hard to do things any other way.

It still probably seems absurd to suggest that it is easier to write something like MS Word or Adobe Photoshop as a web application than as a desktop application, but the initial creation of the software is only part of the cost. The history of Windows may prove prophetic for other desktop applications. They grow and grow, and have all kinds of "baggage" (working with other apps, backwards compatibility, OS compatibility, etc.) Perhaps this weight is even worse for an OS, especially one that offers so many integrated applications with it. But maybe it will prove to be true for lots of other software too.

So why are web applications any different? For one, there is no such thing as backwards compatibility. There is no such thing as "upgrade" for a web application. Thus you never have to support multiple versions and worry about upgrade rates. The use of web standards also makes many of the other issues easier to deal with. Releases can be much smaller, and incremental for a web application, and thus also more frequent.

All of these things may make desktop applications, especially complex ones, just too expensive to build and maintain. It may only make sense to do them online. Desktops may become the realm of small, simpler applications that don't change much (think notepad.)

Sunday, September 10, 2006

Better Late Than Never? NFL Predictions

So I guess I should've posted this before the start of the regular season... but today's action did not change any of my predictions.

  • AFC East -- Miami
  • AFC South -- Indianapolis
  • AFC Central -- Pittsburgh
  • AFC West -- San Diego
  • AFC Wildcard -- New England
  • AFC Wildcard -- Cincinnati
  • NFC East -- Philadelphia
  • NFC South -- Carolina
  • NFC Central -- Chicago
  • NFC West -- St. Louis
  • NFC Wildcard -- Atlanta
  • NFC WIldcard -- Dallas
  • AFC Champ -- Indianapolis
  • NFC Champ -- Chicago
  • Superbowl -- Indianapolis

I would love to pick Miami, but I think they will need one more year. I almost picked Arizona to make the playoffs, and I think Cincinnati will barely make it in.

technorati tags:

Blogged with Flock

Thursday, September 07, 2006

All In The Family

My wife started her own blog today. Apparently I wasn't doing a good enough job of blogging pictures of our kids, so she's going to do it herself! Add it to your favorite personal homepage today!

Blogged with Flock

SMS

I've been doing some research lately on SMS. At PocoPay, we had technology for sending SMS to our customers. For example, if you signed up online you werre sent a pin to verify your cell phone via SMS.

For sending SMS, we paid for a service from Clickatell. We would send them an email and they would then generate an SMS based on the contents of the email. Kind of primitive, but very cheap. PocoPay never made any money so cheap was important!

My latest research has been on receiving SMS. If you're a cell phone user, it is free to receive an SMS, though you must pay to send them. However, for an application provider, receiving SMS is a lot trickier.

SMS is very fragmented, especially in the United States. In the U.S., people like to use short codes for sending SMS. Thus if you want to receive SMS, you need a short code. Only problem is that short codes belong to service providers. So you must pay for the short code from each provider.

Next you still need to receive the SMS. Various service providers will relay the SMS to you either by email or by HTTP POST. Other providers give acess to SMPP networks where you can poll for your messages.

A more primtive route is to do things like cell phone users. This involves hooking your application directly to either a cell phone or a cell modem. Then you can simply receive the SMS on your phone, like an end user would, and then download the SMS to your server. This seems like a good "getting started" option. It's not as expensive, but it does not scale (that's ok for getting started.) Of course you have to connect your phone to a server and need code for interfacing with it, but there are lots of options for this, including some open source ones.


technorati tags:,

Blogged with Flock

Friday, September 01, 2006

XSD

My last post reminded me of a comment a former colleague of mine once made. He accused me of being "anti-XSD." I found this an unusual statement since I have written dozens of XML schemas, maybe more than a hundred. I have made good use of JAXB for generating parsing/binding code based on an XSD from when it was still a proposal up until the present annontation-based versions. So I don't think it's that I'm anti-XSD. It's that I'm anti-XSD proponents, or at least some of them.

You see when I meet somebody who is a huge XSD fan and want to use it to describe the world, I think to myself "I know who you are." These are the same people who used to want to describe the world using relational database schemas. They used to say "build all the data validation into the database, it is faster and better and it has to be right anyways." When they realized that SQL schema definitions were unable to properly describe all real-world data, they turned to stored procedures.

I see the same thing happening with XSD. It was obvious that DTDs were insufficient to describe everything, so XSD was born. It is several orders of magnitude more complex than DTDs, but it still cannot describe everything. It does not allow for dependencies between data. Thus the datatype of one element or attribute cannot depend on the value of another element or attribute (or on the values of four elements and two attributes, etc.)

I've long mused that the existence of the "xs:any" data type was partially because of this shortcoming. I've just picked on of XSD's shortcomings, but that's enough to see that at the end of the day neither XSD and SQL can actually describe the whole world.

So how oh how can we write software for real-world problems when these data modeling languages cannot describe all real-world data? Ahh, that's why we have programming languages. That's why the database guys started pushing stored procedures with their own languages like PL/SQL. Heck, Oracle eventually even put a JVM inside their database so you could write Java for your stored procedures. I wouldn't be shocked to see some kind of language added to XSD.

The truth is you don't need it. There are plenty of programming languages already out there. They can even be used to allow for a declarative approach to data definition. Maybe one of these declarative approaches could become "standardized" or somehow baked into XSD. Maybe one day web browsers (and databases, etc.) will become smart enough to understand "super-XSD" and "middleware", and the programming languages used to build it, will shrink away. I have my doubts though. Those database guys never really pulled it off, and they've been trying since the 80's.

Thursday, August 31, 2006

JSON vs. XML

I recently was dragged into a JSON vs. XML debate. There are definitely some people out there with strong opinions on this matter. I'm not really one of them. However, most web developers I've worked with like how easy JSON is to work with. That's good enough for me. Plus, some of the typical pro-XML arguments are particularly disturbing to me:

  1. XML has strong typing. That's great if you're doing some kind of B2B data/document exchange. Is it really well-suited for the web? Do you want to run a schema-validating XML parser inside a browser? If your server dishes up an XML doc, do you really want your browser to reject it?
  2. XML is extensible. Being able to extend a schema and thus add to a document is great, but do you really want data objects that have a lot more information than is needed by your browser? Perhaps you'll want to wait until the net neutrality debate is over before you answer that...
  3. XML allows your client and server to use the same data model. Again this sounds great, but there are big problems. First, it implies your server is storing everything (or a lot of things) as XML. You better have some really good reasons for doing this, as either your neglecting the considerable strengths of relational data storage or you're probably misusing it. Second, you're creating a strong coupling between the Models and Views in your system. I know this has become more popular as it is viewed as a tenet of "lightweight" development, but it is a design flaw. That doesn't mean you should never do it, just that it must be weighed against the positives that it would bring. In my experience, even when such tightly coupled systems work well at first, they become a nightmare on versions 1.1+

Again, it's not that I'm against XML on the browser... I'm just wary of some of the arguments for it. I think it is often a wash between the two technologies, which is why I say "so be it" when a web dev tells me they prefer JSON because it makes some of the programming easier.

Tuesday, August 29, 2006

Spring MVC and Servlets

I've been using Spring MVC for a variety of web applications. It really does have a lot of nice advantages over Struts making it one of the better request-based frameworks (as opposed to the component based frameworks like Seam.) I came across an interesting use case that doesn't seem to be covered by Spring MVC.

I had a URL mapped to a controller. The URL needed to work for a variety of devices, not just
"full" web browsers like IE and Firefox. In particular it needed to work with a J2ME application. The controller needed to inspect the user agent of the HTTP request, build a model based on this information, and then forward to a view. The view would be different for different devices.

The wrinkle came when the developer working on the J2ME application told me he wanted the view to output a binary data stream. This could be done in a JSP, but is more suited to using a servlet. So I needed to configure a view in Spring MVC that was a servlet.

Spring MVC includes many view implementations. Several JSP-variants, and many other specialized views for working with various technologies such as Jasper Reports, Free Market, POI, PDF, etc. But nothing for a user built servlet like the one I needed to forward to. Seems like kind of a hole in Spring MVC.

Turns out it is not too hard to work around. The key is using the "forward:" prefix. Simply append this to the URL path specified in your servlet mapping, and it will short-circuit the Spring view lookup and forward directly to the desired servlet. So for example, if in your web.xml you had specified "/myServlet" as the mapping to your servlet, then having your controller return something like new ModelAndView("forward:/myServlet", "myModel", model) would forward to your servlet, and allow you to retrieve the model you had built in your controller using a simple request.getAttribute("myModel").

So it was easy to work around, but it still seems like Spring should have a servlet view. Maybe I will try to submit one to them...



technorati tags:,



Blogged with Flock

Saturday, August 26, 2006

Stoned

I've been away for awhile, sidelines for medical reasons. I had a kidney stone that wound up requiring surgery. The surgery was laser lithotripsy. It was the first surgery I've ever had, and the first time I've experienced general anathesia. Recovery from the surgery was actually much more painful than the actual kidney stone, but I was fully recovered in just a couple of days after the surgery. I had suffered with the kidney stone for over a week, and there was no end in sight.

Anywyas, my urologist is running a couple of tests on me in a couple of weeks to analyze my metabolism. This was my second kidney stone in two years, so he wants to see if there's anything in my diet that needs to be changed to prevent me from having another one anytime soon. I'm certainly hoping for as many stone-free years as possible.

Tuesday, August 08, 2006

ESPN FFL and Java Web Start

I've been playing fantasy football for more than ten years. I started playing with friends from college. In fact our fantasy football league was the very first web site I developed. I maintained and enhanced it for a couple of years, passed it on to some of my other friends to run awhile, before we eventually started using a hosted site through CBS Sportsline. I've also played fantasy sports on ESPN for many years. In 1998, one of my fantasy basketball teams finished third overall out of all teams on ESPN. I would've won a leather jacket, if I didn't live in Florida where it was not allowed because it was too valuable a prize and would cause the game to be classified as gambling... I digress.

In short, I've been playing fantasy sports online for a decade. I decided to play on ESPN this year, and had my first draft on Sunday. I was surprised to see that ESPN was now using Java Web Start for their draft application. This mostly made sense as for years they used a Java Applet for it. Actually for several years their applet used Microsoft's Java "extensions" (the ones that caused Sun to sue Microsoft and force Microsoft to stop making their own Windows-integrates JVM) and would only work with Internet Explorer. ESPN has Flash more and more in recent years, so I expected them to switch to that for their draft application.

Instead they've gone to a more powerful Java application requiring the latest JVM from Sun, and used Web Start as a platform for distributing and launching the application from a browser. It's a great use of the technology and I am happy to report it was a very smooth draft. I've had many, many ESPN drafts that were plagued with all kinds of problems, especially in the late 90's. They've seemed to solve all the old problems, and I'm guessing using a more robust application via Web Start was a big part of that solution. Kudos to them.

Not to diss Flash. It has come a long way towards being a powerful application platform. I don't know enough about it to say if ESPN could have pulled off the same thing with Flash instead of using JWS, but JWS was surely a more straightforward upgrade path since their old drafting app was a Java applet.

technorati tags:, , ,

Blogged with Flock

Tuesday, August 01, 2006

Church and State

Here's a great blog about a NY Times article on an amazing preacher. He refused to use his position as a religious leader to endorse politicians or political ideologies. Of course historically religion and politics have gone hand-in-hand. The idea of separating church and state, while not new (see The Greeks) was one of the most revolutionary concepts of The Enlightenment. After all, government that claimed its authority from a god could not be questioned. Thus a separation of church and state was needed so that government would have to derive its authority from the people -- and thus be responsible to the people.

Still, in many governments today we still see religious leaders with tremendous political power. Most people would say "oh that's only the case in backwards, third world countries." Enter Exhibit A: George W. Bush.

Bush was elected (though not without great controversy) but has repeatedly invoked the name of god as an integral part of his administration. He's made statements that he thinks he's on a mission from god. He's used his personal religion to discourage scientific research. He's tried to influence the education system to promote religion over science. His tactic of claiming "treason" when somebody disagrees with his wars is not unique to him or to religious leaders. Still it's no different than claiming "heretic" when confronted with criticism.

There's a huge difference between Bush and the ayatollahs in Iran. Despite his fondness and pride in his religion, Bush is not a religious leader. He has not spent his life devoted to a religious following. No, he is a politician. He simply uses religion. These churches with their American flags and "no gay marriage" banners are just puppets of the GOP.

Saturday, July 29, 2006

Calero Reservoir

Today I cycled the most challenging route I've attempted so far. I cycle out to the Calero Reservoir. This was the longest route (20 miles) I've done, but only by a little. What made it the most challenging is that it's highest elevation I've cycled to, at around 560 feet. My house is around 160 feet, so it's only 400 feet of rise. That rise is over a long distance, though the last 250 feet or so comes in about a 2 mile stretch. Not much by Tour de France standards, but excruciating for me!

Here's a picture I took with my phone of the reservoir:

Nice port-a-potties... And here's the entrance to the park at the reservoir:

It was a fun ride that I will definitely do again soon.

technorati tags:

Blogged with Flock

Friday, July 28, 2006

Fixing Iraq

I have a decent number of news/blog feeds that I read. One thing I try to do is read things that I know I will disagree with. I think it's the best way to keep my mind open. Sometimes it's really frustrating though. For example, today I read this article on the Opinion Journal.

It's a horribly partisan piece, as it quickly reveals in its subtitle "Some alternatives to pre-emptive retreat." So it immediately makes the assumption that exiting Iraq is "pre-emptive retreat." As if leaving a sovereign country alone is retreat, and is if any such exit could not be pre-emptive, i.e. someone would force us out. Such an opening to an article sguarantees that it will never motivate someone who thinks we should leave Iraq to re-consider their opinion. Instead this just becomes a ra-ra article with no chance of having real substance.

The author (name not listed) does offer a single argument against leaving Iraq:

"former U.S. Ambassador Peter Galbraith suggests resigning ourselves to the partition of Iraq into Sunni, Shiite and Kurdish states. The big problem with that idea is that Baghdad is a multiethnic city, and dividing it along ethnic and sectarian lines would entail displacing at least two million Iraqis and a lot more bloodshed."

So we shouldn't let the people there decide their own future because ... they could hurt themselves? News flash: they're doing that already. Too bad for the US that England or France didn't step in 150 years ago to stop us from hurting ourselves in The American Civil War. If only England could have been occupied and guided America, then a lot of American lives could have been saved...

The unidentified author then goes to provide his list for fixing Iraq:

  • More security forces for Baghdad -- Sounds like Vietnam all over again. Just pour more troops in. That's sure to go over well with the population. Even better, "embed" more troops with Iraqi police forces. Yeah that's really going to make people respect the Iraqi police as legitimate authority.

  • Better intelligence -- When all else fails, blame the troops. We've already seen the President do this. I love how some writer for OJ can claim "it shouldn't be as hard as it has been to identify the likely troublemakers." Maybe the CIA should "pre-emptively retreat" and let this guy take over for them. Clearly he could find out who those "troublemakers" are. Just using such a term shows the author's overwhelming arrogance and ignorance.

  • Iraqi leadership -- What's this, an elected Iraqi spoke poorly about Americans? That's clearly causing violence in Iraq. There was probably no violence until these elected leaders started saying bad things about Americans. So we should definitely do as the author suggests and threaten any Iraqis who say things we don't like. That will definitely stop the violence.

  • International support -- He claims that Iran and Syria are supporting the militia groups by giving them weapons, but a bigger problem is "tacit encouragement" from other Arab states. So let the guns and bombs keep flowing in, but get those Arab leaders in line damnit!

  • U.S. resolve -- Hear we go with the typical Republican tactic of all-but-claiming treason on anybody who questions the President. The real reason for violence in Iraq is the Democrats! If you say that you think we should leave Iraq, you are causing violence in Iraq! So shut up before more people die!

technorati tags:,

Blogged with Flock

Thursday, July 27, 2006

The Ups and Downs of Floyd Landis

This year was the first year that I was really interested in the Tour de France. The exploits of Lance Armstrong were always admirable to me, but never that interesting. This year was different.

I started cycling last year. I bike three days a week, usually about 10-15 miles. This year was also the first year of the Tour of California race. The combination of cycling myself and having a major event near my home motivated me to follow the Tour of California. Not only did it come through the Bay Area, but it's two most important stages were in San Jose. This included a time trial just miles from my house. I would have loved to watch the race in person, but I have a job. I still followed it closely. That important time trial was won by Floyd Landis. It gave him a sizeable lead in the race, a lead that he never gave up.

So when the Tour de France came around, I not only followed it, I rooted for Floyd Landis. If you followed the Tour, you know what a tumultous yet glorious event it was for Landis. I could not believe it when he fell from first place to eleventh with just a couple of stages left. I was thrilled when he came back the next day and crushed everyone in the last Alpine stage. I made sure to record the last time trial and rooted him on as he clenched the yellow jersey. It was a lot of fun. It was the kind of thing that cements one as a fan of a sport. My first time following the Tour, the rider I rooted for not only won, but did it in amazing, come-from-behind fashion.

That was last week. Today I was shocked to see that Landis had failed a drug test. I've often said that I don't care if Barry Bonds or whoever uses performance enhancing drugs. Similarly I don't care if Landis (or Lance Armstrong) use them. Still, it was a really bad feeling to read that somebody I had rooted for could have his victory taken away because of a drug test. I can't imagine what it must be like for Landis.

Here's the thing though. I don't think he's guilty. The test indicated a high ratio of testosterone to epitestosterone. If an athlete is using a steroid, it is easy to beat this particular test by also injecting epitestosterone. In other words, if Landis was really cheating, he should not have been caught like this. Further, it takes a long time for testosterone enhancing drugs to be effective. Thus if Landis was taking some kind of steroid, he would have had to have taken for a long time before the failed test. Otherwise, it would have done him no good. If that was the case, then it would be crazy for him to have not failed an earlier test (he had been tested several times during the race including just two days before, as the race leader is tested after each stage.) I guess he could have been taking steroids for a long time, and just forgot to take his epitestosterone. What other "Landis was cheating" based explanation makes any sense?

So I really don't think he was cheating. If that is the case, that makes this an even worse tragedy. It also shows the many reasons why drug testing is stupid. It certainly leads to the possibility of false accusations and unfairly ruined reputations and careers. And as pointed above, it's easy for "true" cheaters to defeat the testing. Not convinced? Look at the human growth hormone scandal in baseball...

Update: Today it was reported that a mass-spec of Landis's urine revealed synthetic testosterone. Ouch. This story just gets worse and worse...

Led Zeppelin

Rolling Stone's cover story this month is on Led Zeppelin. I read the article this morning. It was funny timing, since I had been listening to their first two albums while commuting the last couple of days. Just this morning, I had been thinking that even though so many subsequent artists have been heavily influenced by Zep, their music still sounds very fresh. I think that's a testimony not only to their songwriting skills, but also their musicianship.

I was not even alive when Zep debuted in the late 60's. So it makes it even more interesting to read about how controversial they were. People thought they were over-hyped even before they released their first album. They were often disliked by critics, though adored by fans. The RS article thinks this was the beginning of the rift between "popular" rock and "elitist" rock. That rift definitely exists, but it's hard to think of Maroon 5 as a descendent of Zep... It's also amusing to read that some pundits criticized Zep for being too macho and violent. Take that Tupac.

I started listening to Zep when I was a teenager. For me, there was little controversy in the band. They were a legend, and discovering their music was like finding buried treasure. It was so superior to the glam metal of the 80's. It wasn't like listening to The Beatles or The Rolling Stones. Those groups sounded old to a teenager. Not Zep. Pink Floyd was the only other similar band for me. If Zep still seemed modern, Pink Floyd seemed almost futuristic.

Since then my tastes have matured, and as I've started liking a wider selection of modern music, I also started liking a lot more classic bands. But Zep is still different than any other band. It's like your first kiss.


technorati tags:, ,

Blogged with Flock

Wednesday, July 26, 2006

Worst President ... Ever?

I was reading this little article from Rolling Stone. It came out a couple of months ago, but is still a pretty entertaining read. It asks the question: Is George W. Bush the worst president in the history of the United States?

The article was written by Princeton historian Sean Wilentz. First off, despite the Wentz's attempts to claim some kind of objectivity, the article is very biased. That's too bad, because he makes some very good, and very objective arguments. It's sad that an American historian would make the mistake of being so partisan. He, of all people, should know better. Instead his partisanship simply makes it all too easy for conservatives to dismiss. Of course it may not matter if he makes it easy to be dismissed or not. But if you follow that line of thinking, what's the point of even writing something like this?

I won't dwell too much longer on his biasses, but they are obvious. He claims that the greatest presidents were George Washington, Abraham Lincoln, and Franklin Roosevelt. The inclusion of Roosevelt shows huge bias. FDR's push into socialism is still a divisive issue. Then there's the court packing...

Which leads to Wilentz's other obvious bias. He talks a lot about various scandals that previous presidents have endured. He dismisses the impeachment of Clinton as partisan. This may be true, but it doesn't change the fact that Clinton was only the second president impeached. He mentions several other scandals, but completely leaves out FDR's court packing. This was one of the worst scandals in American history. Newspapers everywhere depicted FDR as an aspiring king or dictator. Wilentz speaks at length about Bush's signing statements policy, as a huge blow to The Constitution, but it's nothing compared to what FDR did.

So there, Wilentz's credibility is quite questionable because of his obvious bias. That doesn't change the fact that many of his other arguments are sound. Bush used lies to lead us into a disastarous war in Iraq. He has used divisive issues to promote hostility between Americans. He has refused to ever admit any mistakes or faults. He has been an enemy of the scientific community. He showed complete incompetence when faced with the Hurricane Katrina disaster.

That's a pretty bad list, but there's more. Just read Wilentz's article. I'm no historian. It's hard for me to say if Bush is the worst president in history. I disagree with Wilentz and think his tax cuts are (mostly) good. I have problems with Bush that Wilentz does not such as the No Child Left Behind program and the Prescription Drug program (Wilentz says these things just need more funding -- again showing his big government/socialist bias.) Still, Bush has been the worst president in my lifetime.

technorati tags:, ,

Blogged with Flock

Tuesday, July 25, 2006

Welcome to Hell, CA

I've lived in the Bay Area for six years now. I went to college in Pasadena from 1992-1997. So in all I've lived in California for eleven years. Hardly a lifetime, but still a decent amount of time. In that time, I've never experienced heat like we've had the last week. I grew up in Florida, and the combination of heat and humidity there is generally much more uncomfortable than any heat in California. So a hot day in San Jose is rarely too uncomfortable for me. That has not been true for this heat wave. It has been unbearable. I am just thankful to live in an air conditioned house and that the electricity to my house has been uninterrupted. Many of my neighbors have not been so lucky, as there have been a lot of power outages. I live in one of the hotter parts of San Jose.

I'm actually a little surprised that somebody has not claimed that this heat wave is more evidence of global warming. I think that would be a pretty dubious claim (even though I think air pollution is a huge problem,) but I still expect it to be made. Lots of people wanted to blame Hurricane Katrina on global warming, and this would seem like an even more obvious conclusion to draw.

The heat has also made me very diligent in venting my car during the day. I always roll down all four windows about 10% and vent the sunroof. I really think that some car maker should put a "vent" button in the car and/or on the fob to the car. It would be great to hit the lock button on your fob and then hit the vent, too.


technorati tags:, , , ,

Blogged with Flock

Monday, July 24, 2006

Liquid Metal vs. Web 2.0

One of the stations that I've been enjoying on XM lately is XMLM -- XM Liquid Metal. I like metal, though I've never been "really into it." It's fun to listen to casually, but it's usually too flawed to listen to intently. Most of the singers try to sound scary, and that's just too humorous to take seriously. Now I do listen to some of the lighter, crossover stuff like Tool and System of a Down. I did buy Slipknot's last record, too, but it really got old after a while. Anyways, it's the perfect kind of music to listen to on XM. You just turn on Ch. 42 while you drive and don't pay too much attention to the singers.

The other thing about metal bands that is really funny are their names. You've probably seen this survey making fun of Web 2.0 company names by comparing them with names of Star Wars characters. You could easily do the same thing with metal band names like Opeth, Chimaira, Unearth, Mastodon, Adema, Motograter, Taproot, Candiria, Brujeria, Atreyu, Dimmu Borgir, Himsa, Soilwork, and Spineshank. I should've thrown some Web 2.0 sites in there just to prove the point, but those are really all metal bands and links to their sites. Many of them have MySpace pages as well, just demonstrating the depth of the MySpace penetration into youth culture. It's not just cheerleaders and student council members using that place, it's the kids who hate them as well.

technorati tags:, , ,

Blogged with Flock

Friday, July 21, 2006

It's Almost That Time Again...

That's right, it's almost time for more Donovan McNabb vs. Terrell Owens barbs. I found McNabb's comments to reporters somewhat amusing, but mostly sad. He's clearly still in the denial stage of the break-up. You know that stage. It's where you are still convinced that you are better off without your ex than you were with them. Just check out a quote like this:

To be honest withyou, the way that you win anything is by winning games.

So it's all about winning games, eh? You see he still thinks they'll win more games without TO.

Even though they went 6-10 last year.

Even though they were 4-3 with Owens and 2-7 without him.

Even though his QB rating with Owens was 87.3 and without was 74.1

Even though he set career bests in yards, completion percentage, touchdowns, and passer rating in his one full year playing with Owens

Yeah, it's all about winning games Donovan. I just wonder what's going to happen when he finally realizes that TO was the stronger member of the duo. TO has made other quarterbacks shine, but McNabb has never made any receiver shine. TO's only full season with McNabb was his 5th best in receptions, 4th best in yards, and tied for 2nd best in touchdowns. One could make a good argument that Jeff Garcia to TO was a better combination than McNabb to TO.

It's going to be a long, long year in Philadelphia. Philly has the worst fans in sports, so they deserve it.


technorati tags:, , ,

Blogged with Flock

Wednesday, July 19, 2006

Hibernate Annotations

Today I found myself in a familiar position -- needing to write ORM backed code. This was a really simple case actually. I had one new table I needed to add plus a class+DAO to access it from my code. Time to call on my old friend Hibernate.

Perhaps I am "old-fashioned" but I usually like to write DDL first. I can see the logic behind writing an object first and then working from there (object -> mapping -> DDL) but it's just easier for me to write the DDL first. So I wrote that and created my table. Then I fired up Middlegen to create my Hibernate mapping. At that point I paused.

Middlegen is great for generating a Hibernate mapping (hbm) file. I decided not to use this and instead use Java annotations. Hibernate Annotations provides full EJB3 Annotation support for any Hibernate application. So I downloaded it and quickly scanned through some of its documentation. I saw that I needed Hibernate 3.2, so I downloaded the latest version of that 3.2CR3 as 3.2 is not GA yet.

I was already pretty familiar with the EJB3 Annotations as I've been one of the many observers to the evolution of that spec. I was ready to write my annotations, but I still needed a class to annotate. So I went ahead and used Middlegen for that. That required me to generate the hbm file, but I simply discarded it when I was done.

Now I annotated my simple class. I'm using Eclipse 3.2 and it handles annotations very well. I simply write the simple name for the annotation, like @Entity and then I could press ctrl-1 to add the appropriate import statement, just like I would do for a class. It also checked my syntax, so it immediately told me that I didn't need quotes for my nullable attribute when I wrote @Column(name="foo", nullable="false").

Now I had an annotated POJO. Next I wrote the DAO class that accomplished my use cases. They were pretty simple, just two methods. I was using Spring so this was especially easy using its HibernateDaoSupport class.

Next I wrote a simple unit test. I told Eclipse that I wanted a new JUnit test case, and it asked if I wanted to do a 3.x or 4.x test case. I chose 4.x, since I was in an annotative mood. Since this was my first unit test that involved Hibernate Annotations, I decided to keep it as simple as possible and bypass Spring. Thus I simply created my Hibernate session factory in my setUp() method, using the AnnotationConfiguration class, of course.

I ran my test and it failed. Not big surprise, don't all unit tests fail the first time? What was surprising was the error message. I had a stinkin' class not found exception. The class that was not found was org.hibernate.loader.custom.SQLQueryReturn. I looked in my hibernate3.jar and sure enough, it wasn't there!

Luckily it was easy enough to Google for this class and that quickly lead me to a thread on java.net. Turns out while Hibernate Annotations needs Hibernate 3.2, it only works with Hibernate 3.2CR2 not 3.2CR3. In other words, if you download the latest Hibernate and Hibenate Annotations, thye don't work together. I went back to the Hibernate site to download 3.2CR2. I noticed that the general purpose Hibernate download page indicated 3.2CR2 as the latest, even though the home page indicated Hibernate 3.2CR3 was the latest and released on July 6.

So I downloaded 3.2CR2 and used it and ... no problems. I did read on the forums that there definitely were problems with that release, I was just lucky enough not to run into them.

Maybe I should put the annotations on the shelf, for now? I'm guessing that it will be stable well before the code I'm working on will be stable, but it's hard to say given their roadmap...

technorati tags:, , , ,

Blogged with Flock