Friday, November 30, 2007

First AIR App: JSON Viewer

I was debugging a problem the other day, and needed to inspect some JSON that was being sent out by a web application. Now we all know that JSON is superior to XML, right? However, one nice thing about XML is that I can grab a blob, throw it into an editor, and have the editor pretty print it for me. This is especially helpful when debugging the XML in question. It makes it easier to spot a mistake in the structure, or to simply navigate to a given value in the hierarchy.

I did some looking around for something to parse and view JSON for me. I found JSON Viewer from CodePlex. It is really nice. However, it is Windows only. I do some development on Windows, but a lot on my MacBook as well. I wanted something that would work on either.

Instead of spending more time looking, I decided to code. A year ago I might have written something in Java, but I decided this was a good chance to write something in ActionScript and leveraging Adobe AIR to create a desktop application. The result is an AIR-based JSON Viewer. It looks really ugly, but I'm no designer. It uses Adobe's corelib to parse JSON and then just massages the resulting object into a structure that can be read by a Flex Tree control.

One fun use of it is to go to some of your favorite sites. Open up Firebug to watch traffic. Look for some JSON, plop it into the app and take a nice look at the data being sent over the wire to your browser (or from your browser in some cases.)  Of course some foolish sites still use XML over the wire, but most of the bigger and/or newer ones use JSON.

Thursday, November 29, 2007

Meebo Platform and ActionScript

It has been a month or so since Meebo announced their "platform." Platforms are all the rage these days, six months after Facebook made everyone envious with their F8 platform. One interesting thing I noticed about Meebo's platform was that they gave you your choice of programming in JavaScript or ActionScript. How nice. So I took a look at their ActionScript support.

Several things jump out quickly, but let's state the obvious ones. They provide a Flash component for Flash 8. Now it's cool that they provide a component (even if "installing a component is arcane), but Flash 8. Seriously? Clearly this is something written in ActionScript 2.0. Now it would be one thing if they wanted to provide some support for AS2 developers, but what about AS3? It just seems crazy for a brand new platform to not support the latest version of one of the two languages it supports. It would be like Silverlight only supporting C# 1.1.

There's also the issue of providing support for the Flash IDE exclusively as well. I guess with AS3 support only, this is all you can expect. The Flash IDE is not made for developers, it is made for designers. Flex Builder is obviously the choice for developers, though it has its drawbacks.

I didn't see if Meebo provides the source code for the SWC. If they did, it probably wouldn't be too hard to compile it for AS3. Actually you might be able to use the AS2 component within an AS3, I haven't tried that. Still, if you're going to launch a me-too platform, at least do it right.

Wednesday, November 28, 2007

Mo' Ram

I've been working some lately with DB2. The worst thing about DB2, at least for a Mac-totin' developer, is that DB2 is not (yet) available for OSX. So what to do? I already had Vista installed on my MacBook via Boot Camp. So I installed DB2 on there and ... developed under Windows. Ugh. Running DB2 and Eclipse at the same time often resulted in not only a slow computer, but Eclipse stack overflows and out of memory errors. Funny how I never had such problems on OSX.

Once that project was done, I decided to upgrade the memory on my MacBook. The max it handles is 2GB (I had the 1 GB that was stock) so I went with that. So where to get the 2GB? Well there is always Apple @$300. Ouch. A better choice is Newegg, of course. For a change though, I found an equally good deal at Fry's, just up the road from my office. 2x1GB sticks of Patriot RAM for $65.

Now it was time to install the RAM. I am always quick to tell people that I am a software guy, not a hardware guy. However, Apple makes it really easy to install RAM on the MacBook. It took me like ten, maybe fifteen minutes total to upgrade the RAM. It could not have gone smoother.

The extra memory has inspired me to give Parallels a try. So far the results are mixed. Every time it launches, I get a message form Parallels saying it is installing Parallels Tools. Then Windows crashes (blue screen.) It reboots and seems ok, but it's still aggravating that it does this every time...

Saturday, November 24, 2007

Black Friday

Yesterday my wife convinced me to go shopping with her and her sister. Normally I dismiss the idea of shopping on Black Friday, smugly stating that people should just buy everything online. Long lines, supply shortfalls (artificial or not,) and the like are all just signs of inefficient markets that will be replaced by the ruthless efficiency of e-commerce. Somehow Crystal talked me in to hitting the mall at 7 AM...

One amusing thing to me is the bait-n-switch items. These are the "limited" quantity items that are offered at a huge discount (do stores actually take a loss on these things?) in order to get lots of people in the store. The store then runs out quickly, so customers wind up buying other, more expensive items. This year's bait-n-switch special was definitely GPS units. Not only did every big-box store out there have sub $200 GPS units in limited quantities, but places that don't normally sell GPS had them as well. Get your GPS at Long's Drugs or Sportsmart, woo hoo!

Black Friday was actually a lot of fun. My niece has managed various American Eagle stores for the last ten years or so, thus I have a lot of empathy for the folks who work on Black Friday. They all seemed to be in a good mood yesterday, and I had a good time joking around with people.

Black Friday had a dark moment for me though. I managed to drop my Blackberry in a (thankfully clean) toilet. I fished it out quickly, and took the battery out of it. I waited a few hours, and it booted it up. The keyboard was crazy though. Sometimes it would not type at all, but other times keys would be entered without me touching anything. So I took the battery back out and left it out over night. This morning everything is working good as new! What a relief!

Yesterday ended on a very bright note. We are going to Florida for Christmas this year, so my wife decided to give me an early present: a Nintendo Wii. She didn't want to try and hide it from me in the luggage, and this way we got to play it with our family in Bakersfield. I am happy to say that I have a sore shoulder this morning from playing Wii Tennis late last night... She asked me if I wanted other games for it, but I really did not expect a Wii and had no idea what games are supposed to be good on it. I will probably get Madden for it, just because I used to love Madden on the PS2 and Gamecube. Guitar Hero looks like a lot of fun, too. I have basically taken the last 3.5 years off from playing video games, as I stopped having time for stuff like that when we started having babies. I'm not sure how much time I will have to play it now either, maybe once I finish my book :-)

Tuesday, November 13, 2007

The Network Application Pattern

    Several years ago I worked in consulting. My company was hired by larger companies to build web applications. We worked on internal web applications, external ones, and even some that were completely consumer focused, like the Washington Post Jobs site. Often we wrote applications that replaced existing desktop applications. Many of these were so called thick clients or client-server applications.
    The list of technologies was all over the place: PowerBuilder, Swing, and Visual Basic. The reasons for the conversions were pretty similar though: make things more easily accessible. It was much easier to say “you need InternetExplorer 5.5 or higher” to run an application, than it was to require somebody to download and install, and stay upgraded to the latest version of an application. The hardest part about these conversions was trying to reproduce all the functionality. You just could not do it, and there were always compromises that you had to work out with the clients on this.
    These days I am starting to think that such compromises are unacceptable. The days of the thin client are coming to an end. At the same time, the days of the thick client are not coming back. Instead a different pattern has emerged, and it is going to win. I call it the Network Application, though other folks have different names and different takes on it. Here is what it is.

Misuse of Big Iron

    To make things as accessible as possible generally meant to require as little as possible on the end user’s machine. The browser wars necessitated this as well. Inconsistencies across browsers required a least common denominator approach. The browser become a rendering device, and nothing else really.
    All the computation required to determine the interface shown to a user was performed on servers. For awhile these servers were Big Iron -- look at how well SUNW did in the late 90’s. Moore’s Law caught up and lots of cheap servers replaced Big Iron, but the usage pattern remained unchanged. Programming languages flourished around this. Look at all the UI frameworks in Java, the explosion of PHP, and the emergence of Ruby on Rails.

Another Shift

    I am not one of those melodramatics who look for a single event and say “this epoch caused everything to change.” Things started changing. Browsers stabilized and Moore’s Law kept moving along. Microsoft’s attempt at subverting web browsers by creating IE-only extensions, ultimately backfired on them. They created XMLHttpRequest, which ultimately allowed for exactly what the Netscape think tank had always hoped for and Microsoft always feared: web applications that were on-par with desktop applications. Well sort of...
    Web applications still have a lot to be desired. As I mentioned earlier, it can be really hard to reproduce a desktop experience in a browser. There are a lot of things going on to solve that, and some of them might even work. Orthogonal to the technologies at play is the pattern of how to program applications that are as feature rich as desktop applications, but can be run from a browser with no software to download or worry about updating.

The Pattern

    The key to the pattern is to stop using servers for creating user interfaces. If you like to think of UIs using the popular Model-View-Controller paradigm, the server should only be a place for Models. Your View and your Controller should be running on a client computer, not a server. Your server will probably serialize a Model to send to the client so it can use it in a view, but otherwise the boundaries should be very clear.
    Why does this help with the problem of creating desktop-like applications? Because when all the view logic is located on the client, there are no limitations to the interactivity. For an example, think about infinite scrolling like you see in Yahoo Mail (I usually rip on Yahoo, so I thought this would be a nice change of pace.) If the view of the list of your emails is formed on a Yahoo server, then to scroll past the bottom means recalculating that view on a Yahoo server, even if it is to show one more email that is just past the bottom of the list. If you had to do it that way, you would not allow scrolling. You would force pagination, like GMail does. However, if you already have the code for creating that view on the client, then all you need on the client is the data to display.

Servers Are for Services

    The beauty of this pattern is that your servers become specialized in serving up data, not HTML. There is still some overhead in de-serializing the request and serializing the response and making it all work over HTTP, but it’s a lot less than the alternatives. Of course it’s not a read-only world, so you’re not just sending out data. You are also receiving changes to the data, either directly, or (hopefully) via a service interface. Just because we’re getting clever with our presentation design, doesn’t mean our middle-tier design can be garbage.
    Notice I used the Service word. This is the same word used by those SOA guys, and it means the same thing. There’s no reason that the clients that you build for your service (in this case user interfaces) cannot leverage the same infrastructure that clients built by other folks use. Now you may want to expose more services to the user interfaces that you built, or maybe you don’t... The point is that if you decouple the so called business logic of your system, then it is easy to build Network Applications that provide rich user interfaces to the end users of your system.

Implementations of the Pattern

    Like most patterns, this was one has emerged from implementations. It is not something I dreamed up in my ivory tower in San Jose. One of my favorites is the Google Web Toolkit. GWT let’s you build things kind of like you would for the old-school thick clients using Swing, but it turns around, turns everything into code that runs on the client. One of my friends was starting to learn GWT recently and I think he was surprised when I told him that everything in GWT becomes static assets that can be served up by any web server directly. They are very cache-able assets as well... There are GWT ways to hook up your server calls as well, and of course this does require a Java application server. But that part of your code can be done in JavaScript, using GWT’s JavaScript Native Interface (JSNI.) The nice thing about using the GWT server code is that you get to use the same object model on client and server.
    GWT is tied to JavaScript, and thus it inherits the limitations of JavaScript. My other favorite implementation of the pattern is Adobe Flex. Flex Builder 3 even has code generators for creating Java or PHP data services for communicating to your Flex application. Flex applications run inside the Flash player, and don’t have nearly as many limitations as JavaScript applications. Flex applications are usually much bigger than JavaScript ones, but are also very cache-able. Bandwidth is becoming less of an issue in terms of user experience, though it is still a cost issue.

The Moral of the Story

    If you are a UI engineer, you should not be writing HTML. You should only be writing code that executes on the client. There are many other options out there. In the JavaScript world, there’s Dojo’s Dijit, the Yahoo UI Library, even script.aculo.us. Ruby on Rails’ RJS has some similarities to GWT, but is not there yet. The Rails guys are still perfecting the last generation of web applications, and have not moved on yet :-) Straddling the JS and non-JS worlds is OpenLaszlo. I would be more enthusiastic about Laszlo if it was using new Flash technologies. On the non-JS side, the two chief non-Flash entities are Microsoft’s Silverlight and JavaFX.
    Now again, these are all technologies that can be used with this pattern. They can also be used outside of the pattern, though I would say that is probably a mistake :-)

Friday, November 09, 2007

FUD by Doug Crockford

I like some of Yahoo's Doug Crockford's ideas on JavaScript. So I watched this talk by him on the State of Ajax. It has a great buildup on the history of computing and comparing pre-Ajax web apps to the IBM 3270. He's also a clearly opinionated guy, but he really lets this influence his statements. Examples...

He claims that Java applets failed primarily because of "write once, run anywhere" was a broken promise. That's ridiculous. First off Java applets only needed to succeed on Windows, so write once, run anywhere was irrelevant for a desktop technology. He does correctly state that Java UI (AWT) was no good. He commits a lie of omission, by failing to mention Microsoft's JVM infringements. He then says that Java succeeded on the server because (wait for it) write once, run anywhere is not an issue on the server. Not only is this wrong, it's the opposite of the truth. When I first started writing Java server apps in 2000, I was writing it on Windows and deploying it to Solaris.

Next he heaps praise on JScript and says that its "bugs" were just reproductions of Netscape's bugs. There is some truth in this, but it certainly shows his bias. He states that JScript inveted XMLHttpRequest and that there no innovations for five years after that until Jesse James Garret "discovered" Ajax.

He completely ignores Flash. Earlier he states that write once, run anywhere is really difficult and anybody that can pull it off deserves credit. Well Flash pulls it off. He claims that JavaScript pulls it off, but that's just plain wrong. I don't know how somebody who knows JavaScript so well can state this. He's smart enough to know all about doing browser sniffing and conditional logic based on the results of that sniff.

Thursday, November 08, 2007

Flock 1.0

In case you missed the news, Flock finally went 1.0 late last month. I've been playing around with Flock for over a year. They're integration with social services has gotten better and better. I did a clean install of it and setup my Flickr, YouTube, and Blogger accounts very easily. I've given up on using it for RSS, as having a server-based solution (Google Reader) is too valuable to me. They've also added Facebook and Twitter integration, two favorite services of mine. Both are well done. And of course it's based off Firefox 2.0 now, which is great. Most Firefox plugins work great with it. I'm using its blog writer right now, as I'm planning on using it as my primary for a week or so and then figure out if I should go back to Firefox or not.

Blogged with Flock

Saturday, November 03, 2007

Big Foosball Gamez

I thought about writing about Open Social, but I'll leave that to Terry for now. Besides, football is more interesting, at least this week. I'm very pleased to see Florida's defense finally stop somebody, even if it was just Vanderbilt. Vandy's defense was ranked #14 in the country, which just shows how good Florida's offense is. Last week's game against Georgia would have been a lot different if Tebow hadn't got his shoulder dinged the week before. He's Florida's "conservative" offense, i.e. their ball control offense. The running game is an option running game, i.e. it is geared towards big plays. I'm not saying Florida would have won, that would be crazy. But Georgia had plenty of time to expose Florida's weak run defense, and boy they did a good job of that!

Anyways, the NFL is where all the hype is this week. That's one nice thing in college football. You have a lot of "game of the year" type games, seemingly every week. That's a direct consequence of the no playoff system where every loss is potentially catastrophic. People want a playoff (me included,) but just remember what you'll lose if you get that. This week has a game of the year in the NFL: New England at Indianapolis.

I hate New England. I'm a Dolphin fan (please no snickers) so I have to hate them. But I respect them. I respect using technology to "cheat". I so wish Miami was doing that, though I wouldn't want them to get caught. They really need those draft picks. I also respect running up the score. This is not high school or even college (both places where you see much more running up the score) where you could maybe have sympathy on an over-matched team. Nope, it's the NFL: home of the Marxist salary cap. Everyone is making crazy money, including the coaches. There's no room for sympathy. Now, personally I would probably be more careful about exposing my starters to injuries in meaningless games, but whatever. That's their risk to take.

All that being said... I hate New England. I don't mind Peyton Manning too much. After all, he never beat Florida and he can never change that. So go Indy.

On a more a logical basis, New England's offense doesn't match up that well to Indy's defense. The whole premise of Cover-2 is to minimize big plays. It takes a big armed QB to hit the deep gaps in a good Cover-2, and Tom Brady does not have a big arm. That doesn't take anything away from him. Brady is one a few great QB's without a great arm. Cover-2 with good safety play should neutralize Moss and Stallworth. I still think teams should be able to run on Indy, but have a hard time believing that New England will be the first team to do that effectively.

Indy's offense is more diverse and has been executing against defenses every bit as good as New England's. Recent history seems to indicate that Belichick has not been able to "solve" Peyton Manning for the last couple of years. Without a strategic advantage, New England's defense does not stack up well against Indy's offense. The opposite cannot be said. So, clearly you gotta go with the home-dog Colts.

Friday, November 02, 2007

ActionScript Getters and Setters

It's always nice when a programming language surprises you in a pleasant way. ActionScript 3 has get/set property syntax, very similar to C#:


public class Person implements IPerson
{
private var m_name:String;

public function get name():String
{
return m_name;
}

public function set name(value:String):void
{
m_name = value;
}
}

What was an even nicer surprise is that you can define properties in an ActionScript interface:


public interface IPerson
{
function get name():String;
function set name(value:String):void;
}

And then write code that makes it look like you're accessing the field of an inteface:


var person:IPerson = new Person();
person.name = "Michael";

Now if only we had this syntactic sugar in Java... 

Wednesday, October 31, 2007

Bad Writing

I like reading Marc Andreessen's blog. He has good insight. Today I saw the news about Google's Open Social initiative. I noticed that Ning was a participant, so I figured Marc would have something interesting to say about it. Reading his entry reminded me of many other entries by him and how incredibly annoying his writing style is. Let me give some qualification to this statement.

My 10th grade English teacher, Dr. Deluzain, was really tough. He made all of his students write a lot, and he absolutely tore up everything you wrote. I give him tons of credit for making me into a decent writer. In college, the biggest advantage I had over other Caltech students was not my mathematical abilities, it was my writing skill. Math bailed me out in many situations, and led to my only A+ (in quantum chemistry if you can believe that,) but I was always the best writer in every "soft" (literature, history, political science, etc.) class I took. Thanks Dr. D.

One of the lessons I learned from Dr. Deluzain was that you should never use styling in writing. This was 1991, so word processing had become popular. Of course people wanted to use bold and italics, or large fonts, to drive home points. Dr. D. taught me this was obnoxious and unnecessary. It showed poor skill. If you had to resort to such tactics to emphasize your point, then obviously you were doing so to make up for a lack of writing skill.

Fast forward back to the pmarca blog. Andreessen has to be the worst person I've ever seen at using italics and bold all over the place. Normally I just ignore it. College taught me that most technical people never need to hone their writing skills, so why should Andreessen be any different. The first full paragraph (most of his first few paragraphs are actually just sentences, but I digress) has 102 words in. Of those, 27 words are either bold or italics. Of the other 75 words, 21 are in quotations, which is a similar sign of poor writing (one I'm guilty of too, though it's not quite as bad.) It just makes my head hurt. I hate being a writing snob, but I needed to vent and that's part of what my blog is for.

I dislike writers who can only bring up negatives and never offer solutions to problems. So I decided to re-write his paragraph. I tried to keep his words as much as possible.

"Technically, Open Social is implemented as what I call a plugin API, or a Level 2 platform. In other words, it's not a web services API -- rather, it's a way for external applications to plug into a host environment (container). The external app literally shows up insides the pages of the container, and can make Javascript calls to retrieve information from the container and perform functions within the container. For example you can make a Javascript call to get a list of all of the user's friends, or to inject an event into the user's activity feed."

Isn't actually a lot less work to write it like this? Or has the web redefined good writing style? Maybe my way is antiquated and Marc's is exemplary...

Monday, October 29, 2007

A-Rod's The Man

Why is A-Rod leaving New York? Why did he announce it last night?

I think A-Rod is leaving because he can. He doesn't like it there, and can at least get the same money somewhere else. People keep saying "Boras must know that they can get better money from another team" but I don't think it has to be better. And that answers the second question.

The best way to sell A-Rod is not on his stats, as impressive as they are. The best way to sell him is on his potential economic impact to a team. The best way to emphasize that is to make sure that A-Rod is the story in baseball. That would not have happened if Boras had waited ten days past the World Series to announce A-Rod is opting out of his contract. Nope. But by announcing it while a lot of people were still paying attention to baseball, i.e. during the World Series, then he smoothly transitions all those World Series watchers into A-Rod watchers.

Boras doesn't have a deal in place already. He's going to have to work for his money, and this is part of how he's going to do it. His client wanted out of New York, and he's just doing his best given that situation.

So all the idiot Yankees fans (which is not all of them...) are getting their wish. No more A-Rod. The Yanks have a lot of money to spend on replacing A-Rod, so that should make for an interesting offseason in the Bronx.

For what it's worth, A-Rod has clearly made the right decision. Any other city would have worshiped A-Rod unconditionally before this season, and would be ready to rename their city after him at this point. I should know, I live in the Bay Area. Barry Bonds is the worst player to root for in baseball history since Ty Cobb, and he is completely adored in San Francisco. A-Rod is nowhere near as unlikeable as Bonds and is almost as good (especially if you consider position.) Plus look at the "new" ownership of the Yankees. They parted ways with Joe Torre and now A-Rod, and in both cases the owners felt the need to talk trash to the press. How old are these guys? It's just amazingly juvenile.

Mac Java 6

There's been a lot of developers upset that Leopard does not include Java 6. Does this make the Mac a poor choice of Java developers? No, it doesn't, not yet at least.

First of all, I fully expect that Apple will release an update to Leopard that will include Java 6 before the end of the year. But it doesn't matter too much because Java 6 was mostly a performance release for Sun. There's some nice things in the Swing implementation included on Hot Spot. Neither one of these things is even relevant for Apple. There are some language features (debugging, StAX parser) but these are pretty minor.

So to me it doesn't matter too much that there is no Java 6 for the Mac. Oh, but there actually is, or was. I personally had some problems with it, so I wasn't too surprised that it's no longer available from Apple.

Things only become problematic if Apple takes a long time to support Java 7 when it comes out, especially if you assume there will be a lot of language changes in Java 7. If that happens, then it could be conceivable that developers won't be able to use OSX. Others have pointed out that a major litmus is Eclipse. If Eclipse will run on OSX, then all is well. Eclipse 3.3 was released just a few months ago and was the first version of Eclipse to require Java 5... Eclipse is obviously important for Java developers, but also for Flex developers and even PHP developers.

Sunday, October 28, 2007

MoneySox

Obviously the Red Sox sweep was not surprising to me. I'm not a particular fan of the Red Sox, even though I thought they would win the World Series. If there is one endearing quality about them it's that the Red Sox are in a lot of ways an affirmation of Billy Beane and his analytic approach to baseball made famous in Michael Lewis's Moneyball. Theo Epstein is definitely from the same school of thought as Beane and it shows. The 2007 had a distinctive Moneyball feel to them, with patient hitters like Dustin Pedroia and Kevin Youkilis (Beane's "Greek god of walks" after all). Hideki Okajima is so reminiscent of Chad Bradford in Moneyball, and you could easily imagine Billy Bean building big stats for his hard-tossing closer, Jonathan Papelbon, and then trading him for a slew of underrated talent. Of course The A's would never have the money to sign other guys that Beane would love like David Ortiz, Manny Ramirez, J.D. Drew, and Mike Lowell. Would Beane like a guy like Josh Beckett? He typifies a lot of what Beane avoids (big, hard throwing right hander) though he certainly has put up some impressive numbers over the years. Anyways, if you're a fan of Billy Beane and Moneyball, then you probably had to root for the Red Sox.

Thursday, October 25, 2007

TextMate and the Weak Dollar

I started using TextMate as it is very popular with the Ruby on Rails crowd and I am writing a book on Rails. It is a great product, and I like using for all kinds of things now. So once my 30-day trial expired, I decided to purchase it. They use PayPal for processing payments, and they charge you in Euros. Luckily, PayPal easily handles the conversion for us Yankees. This brought a brutal reminder of just how weak the US Dollar is now:




1 U.S. Dollar = 0.68 Euros ... Ouch! Suddenly TextMate seemed like a pretty expensive text editor. I still bought it, but it really made me second-guess the most recent Federal Reserve rate cuts. That gives me one more reason to vote for Ron Paul!

Wednesday, October 24, 2007

Flash CS3 and SWCs

A co-worker called me up recently to ask me how to use a SWC with Flash CS3... A SWC is a collection of compiled ActionScript classes, similar to a DLL or JAR. They are very easy to use with Flex Builder and the Flex compilers. In this case, there was a SWC that I had created that my co-worker wanted to use in his Flash project. I knew that this was a pain. 

Flash CS3 thinks that SWCs are for UI components. You can create a SWC with a manifest.xml (in Flex Builder), drop it into your components directory, and use it. That's great for UI components, but not for class libraries.

On an older project, the developers using my library just linked to the source code directly to compile. I told the new developer to do that, but he quickly pointed out that the new version of my library used Adobe's corelib library... which is also a SWC. 

So the first thing I did was take the source of corelib and zip it together with the source code of my library to give to the developer. Now he could work while I solved this SWC problem. I saw a post on the corelib group site, but it did not quite solve my problem. So I emailed one of the corelib developers from Adobe.

He thought I should be able to add any SWC to the CS3 project's classpath (file->publish settings -> flash.) That did not work. I was able to compile against classes in the SWC, but got runtime errors equivalent to a Java NoClassDefError. 

About the same time, I was reading some documentation on PureMVC, an AS framework that looks promising to me. I noticed that it was supposed to be able to work with Flash CS3 and it was distributed as a SWC. I read the install directions for CS3 ... they indicated that you needed to use the source code, not the SWC.

So now I'm thinking that there may not be a solution to this problem. Maybe this is a bug in Flash CS3?

Monday, October 22, 2007

World Series Predictions

My LCS predictions wound up being pretty good! I started writing this a couple of days ago and forgot about it. Now I've got to finish it as the first pitch is being thrown...

Rob Neyer speculated a 60% probability of Boston winning. That seems pretty plausible from a statistical point of view. Boston has better hitting and much better pitching. I've seen some nonsense about how Colorado's pitching was great after the All-Star break, but that is a cherry-picked stat. Maybe it was great because they played more road games and against lesser competition? Their line-up stands up pretty well side-by-side to the Red Sox, but their pitching is not even close.

So... yeah Red Sox in 5 seems appealing. That would have Beckett getting a chance to clinch, though it would be at Coors Field. 

Sunday, October 21, 2007

Ning Code

I was leisurely sifting through feeds in Google Reader when I came across a new one from the Ning dev blog. It was about enabling public feeds in private networks. They explained why this was a hard problem (it is) but how you could enable it given some security caveats (so far so good.) One of the keys is changing the source code for your network, which is very cool. That's where the coolness ends. Here's an excerpt:

To change the display code, first visit the file /lib/XG_TemplateHelpers.php and find the function xg_autodiscovery_link(). Remove the if (XG_App::appIsPrivate()) { return; } text (but leave the ?> at the end of that line.)

Next, visit the various templates that might display RSS links. These files are:

  • /widgets/forum/templates/category/list.php
  • /widgets/forum/templates/topic/list.php
  • /widgets/forum/templates/topic/show.php

That list is actually much longer, but you get the point. Umm, hasn't anyone here ever heard of encapsulation? PHP supports OOP, or at least enough of it to easily hide this particular flag so you don't have to remote it in twelve places!

Saturday, October 20, 2007

Attributes vs. Elements

I was reading an article on developerWorks that I didn't write... It was about XML and Java. Sound like a tired, old subject? This had an interesting take: How the choices you make when writing XML influence your Java application code. One of the central themes was on using Attributes vs. Elements. One of the basic points was that using attributes leads to faster code. I decided to test this theory.

I took a pretty simple XML document. It was actually one that I had written recently for a real problem. I created two versions of the same document. One used elements exclusively. The other used attributes whenever it was possible. I then tested how fast it was to access two pieces of data. One was "shallow", i.e. near the root of the document. The other was heavily nested. In both examples, the data was an attribute in the attribute favored approach. I repeated the test over 10,000 iterations and tested it against three XML parsing technologies: the standard DOM implementation included with Java 6, using XPath with dom4j, and using the StAX implementation included with Java 6. For the DOM and dom4j techniques, I also examined the parsing time.

The results were a little surprising. I found no differences with attributes vs. elements for DOM. This was true for both traversing the tree and for parse time. I don't mean a negligible difference, I mean no difference at all. It was so surprising that I had to double check my code a few times. The big difference for DOM was that the code for the attribute favored approach was definitely simpler, which was one of the points in the developerWorks aritcle.

The dom4j story was different. It was slightly faster to parse the attribute document, but it was a bit faster to retrieve values on the element document. I was surprised by this, but the differences were very small, probably not statistically significant (I didn't test this, though.) The code was virtually identical, of course, since we were using XPath for the traversal. The dom4j was much slower than the DOM approach, which is again not too surprising.

Finally, the StAX tests showed faster results for the attributes document. There was a larger difference than in any of the other tests. This makes sense because you don't have to go as far in to the attributes document (a start element event contains the attribute data, but does not contain text child node) and there are less events fired in an attribute document vs. an elements document. For example, bar is three events, but is two events. Also, StAX was faster than either DOM or dom4j, as you would expect. The StAX code for the attributes document was also slightly simpler than it was for the elements document.

So if you're using DOM or StAX, you should definitely favor attributes over elements. It will be less code and in the StAX case, faster code. If you're running dom4j and XPath (or maybe XQuery) based navigation, then it doesn't matter as much and elements based seems ok. This really is important, as a lot of these "modern" RESTful web services are heavy on the elements format over the attributes format. This is doubly bad for web services, since there's obviously a much larger byte-cost on elements style documents.

Update: As request, I am attaching the source code I wrote for this little micro-bench. I tweaked it a little as I realized there was an inefficiency in one of my dom4j methods. This tweak made dom4j faster on the attributes document, which is more consistent with the rest of the results. To run the code, you need dom4j and you need either Java 6 or Java 5 plus a StAX implementation. I ran it on my MacBook under Java 5 using Sun's StAX parser.

Friday, October 19, 2007

GWT and XForms Series, Parts 3 and 4

The last two parts of the GWT and XForms series I wrote for IBM are up now: Part 3 and Part 4. Part 4 is fun since it is more "icing on the cake" kind of stuff as opposed to the core integration of the two technologies. I really wanted to work in some info GWT's ImageBundles. It's a slick implementation of the CSS sprite pattern.

Continuing down that tangent... I'd like to see an ActionScript implementation of that pattern. It would be cool to take a dozen images in Flex Builder, have it create a composite, and then use that for any references to those images in your Flex application. Of course maybe it's not needed. If you knew you needed those dozen images for your app, you could just embed them all in your SWF. That's going to be even more efficient since you won't have to make the HTTP request for the composite image. Obviously there are advantages to externalizing, since you could change the composite image without recompiling your SWF and without having to worry about referencing a new version of your SWF that's not being cached by users. It also allows for localization of the images. Enough rambling on that topic for now.

Wednesday, October 17, 2007

New IBM Tutorial on XUL

I wrote a tutorial on XUL for IBM. It's a very introductory look at XUL. You can do some seriously crazy programming in XUL. The focus of the tutorial is on how web skills can be leveraged in XUL. Adobe AIR is getting a lot of press right now (and deservedly so) for letting web developers bust out some desktop apps. XUL lets you do the same thing. It's definitely a little more complicated than AIR, but also much more powerful. XUL gives you access to a lot more desktop resources than AIR does. Plus, if there's something that it doesn't already give you, then you can just write some native code and expose it via XPCOM. I think a lot of AIR developers are already begging for this kind of extensibility.