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.