Thursday, March 27, 2008

Beta Browsers 2008

This is a big year. Both IE and Firefox will release new versions this year. That hasn't happened ... ever? IE8 had its first beta, whereas Firefox 3 is at beta four. Indeed FF3 is much more polished at this point than IE8. However, I must say that Microsoft has been smarter than the Firefox team in a number of ways.

First, IE8 includes an improved IE Developer Toolbar by default. The IE DevBar is roughly equivalent to Firebug, but Firebug does not work with FF3. Of course you can’t really blame this on FF, but IE8 is much more web developer friendly. Web developers are the primary (only?) audience for beta browsers. IE8 also includes the IE7 emulation mode. Again this is very nice for web developers who have to program for IE7 currently, but need to get a head start on IE8 (wait, isn’t that all web developers?)

Vista Annoyance #432

A few weeks ago, I watched Guy Kawasaki's interview of Steve Ballmer at MIX. Kawasaki gave Ballmer a hard time about Vista. It made me think of some of the problems I have had with Vista. I started thinking "well things seem better now.' Then this morning I try to log on to my home system and get an error message saying that Windows could not load my user profile. In the event viewer it says:

Windows cannot load the locally stored profile. Possible causes of this error include insufficient security rights or a corrupt local profile.

DETAIL - The process cannot access the file because it is being used by another process.

Luckily I rebooted and everything was ok. Yep, rebooting is still the best way to fix most Windows problems. Things haven't changed much in the last fifteen years.

Actually I still have other problems with Vista. I still get problems caused by Windows Firewall. Vista was so unstable on my MacBook under Parallels that I replaced it with XP. In December, my Vista install was completely corrupted. After several minutes of use, its network and memory consumption would go ballistic making the system unusable. I thought at first it was a virus or malware of some sort, but I never found any evidence of either. I wound up re-installing Vista to fix the problem.

Now Vista SP1 is out. I don't know if I should be hopeful that it will be a remedy for all of my pains ... or if it will just be fuel for the fire and cause me to "upgrade" Vista to XP.

Wednesday, March 19, 2008

eBay on developerWorks

I have written a lot of articles for IBM over the last couple of years. Most recently I got a chance to write about "my day job" if you will: eBay. I wrote two articles on how we use Eclipse at eBay to tackle a lot of interesting problems. When I first came up with the idea for the two articles, it seemed really cool but I was a little worried about it being complicated. When you think of a large company (and with 15,000 employees and a $36B market cap, eBay certainly qualifies) you think of all kinds of red tape, armies of lawyers, etc. I was pleasantly surprised to have almost none of that to deal with for these two articles. The articles definitely show some of what's "under the hood" at eBay, but its just enough to explain some of eBay's unique needs and how we have used Eclipse to help with these needs.

Monday, March 17, 2008

Go Disney?

A friend of mine got the following email:
Dear Parent of Chris,
We're pleased to inform you that your teenager has registered with us
and will now have access to the Internet sites of the
Walt Disney Internet Group ("WDIG") including Disney.com, ABCNEWS.com,
ABC.com, ESPN.com, FamilyFun.com and many more!

As a result, we want to make you aware of all of the information below:

1. Participation in WDIG Site Features. Now that your teenager is
registered with us, he/she can participate in all of the features we
make available on our sites to registered guests under the age of 18,
including games, sweepstakes, contests and interactive features on our
sites through which personal information can be made public to the
Internet and shared with users of all ages (i.e., "Public Forums").
// Random B.S. omitted

2. Terms of Use. Use of all WDIG Sites is governed by the
"Terms of Use" posted at the bottom of each WDIG Site.

The Terms of Use contain important provisions governing your, your
teen's and our rights including acceptable conduct on the WDIG Sites,
intellectual property rights (for example, our right to use
information, content and materials submitted to us by your teen) and
other rights available to you, your teen and us. We ask that you
read the Terms of Use and ensure that you understand them. If you
do not want you and your teen to be bound by these terms, you must
revoke your teen's registration. If you revoke your teen's
registration, your teen will not be able to access any portions of
the WDIG Sites that are made available only to registered guests.

Click below to view the Terms of Use:

http://disney.go.com/corporate/legal/terms.html

By not revoking your teen's registration, you agree that you and your
teen will be bound by the Terms of Use in connection with his/her use
of WDIG Sites and you agree to personally ensure that your teen
complies with the Terms of Use. (emphasis added)

If you want us to revoke your teen's registration, click below:

// link removed
How awesome is Disney! Under-age? No problem. Go ahead and register on their site. Then your parents will receive an email and have to read it and click on something to revoke your registration. Or better yet, just use a bogus email for your parents to remove the off chance of them actually reading the email and being responsible.

That is clearly the case here in fact. My friend has no children, so clearly some child picked a random email address that happened to be my friend's. Now if that child will start publishing plans to blow up buildings on a Disney forum page, my friend can be held responsible (per the Terms of Use.) Lovely!

Thursday, March 13, 2008

Silverlight Stocks

Ever since details of Silverlight 2.0 came out, I planned on re-doing my stocks app using it. This is an app that I first wrote for a GWT tutorial I did for IBM, and then re-wrote when I learned Flex last year. I wanted to write it in Silverlight last year, but Silverlight was not ready then. Now it is. Here's a picture of it.


This look-and-feel is all defaults. It looks like a web page! It's usually easy to spot Flex apps, but that is not as true with Silverlight. Everything works the same as with the Flex or GWT versions, except the color-coding for stocks that are up or down. I figured out how to define styles with Silverlight (more on that) but could programmatically set the style. Let's take a look at the code. First the UI code.


<UserControl x:Class="SilverStocks.Page"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Enter Symbol "/>
<TextBox x:Name="symbol" Width="100" KeyDown="symbol_KeyDown"/>
<Button Click="Button_Click" Content="Get Info" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Company Name: "/>
<TextBlock x:Name="company"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Price: "/>
<TextBlock x:Name="price" Text="$"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Change: "/>
<TextBlock x:Name="change" Text=""/>
</StackPanel>
</StackPanel>
</UserControl>


Pretty similar to MXML, but distinctive. As with ASP.NET pages, Silverlight puts all code in a code-behind file:


public partial class Page : UserControl
{
const string url = "http://localhost:8080/Stocks/Stocks?symbol=";
public Page()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
invokeStockService();
}

private void invokeStockService()
{
string symbol = this.symbol.Text;
WebClient service = new WebClient();
service.DownloadStringCompleted += new DownloadStringCompletedEventHandler(handler);
service.DownloadStringAsync(new Uri(url + symbol));
}

private void handler(object sender, DownloadStringCompletedEventArgs args)
{
if (args.Error == null)
{
this.showInfo(args.Result);
}
}

private void showInfo(string xmlContent)
{
XDocument root = XDocument.Parse(xmlContent);
var stocks = from xml in root.Descendants("stock")
select new Stock
{
Symbol = (string) xml.Element("symbol"),
Company = (string) xml.Element("companyName"),
Price = Decimal.Parse((string)xml.Element("price")),
Change = Decimal.Parse((string)xml.Element("change"))
};
foreach (Stock stock in stocks)
{
this.company.Text = stock.Company;
this.price.Text = stock.Price.ToString();
this.change.Text = stock.Change.ToString();
}
}

private void symbol_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
this.invokeStockService();
}
}
}


Notice that I used the LINQ-XML cleverness, as advocated by Scott Gu. Most dynamic language folks will probably favor ActionScript's E4X over using this lambda-ish query language and a statically defined class. Actually I'm sure I could refactor this to not use the class at all, and just set the text fields during the query.

Finally, the other major difference between the two is the Flex framework's mx:HttpService. This component encapsulates the call to the back-end and provides dynamic binding. There is no handler code in the Flex version because of the binding. Will data source bindings and components like mx:HttpService find their way in to Silverlight?

Wednesday, March 12, 2008

JsonViewer Updated

Some folks pointed out that the JsonViewer installer was complaining about being on the wrong version of AIR. That was because I wrote it before AIR went 1.0. So I thought "no problem, just re-compile it." Well sort of.

I updated Flex Builder 3 to the GA version and updated AIR to 1.0. I imported the old project. It picked up my Subversion settings and what not, very nice. I did a new "export release version" and it worked just fine. I tried to execute the .air file and it bombed. It told me that my AIR file was damaged.

WTF!? I tried to run the app directly from Flex Builder. It did nothing. No errors, just nothing. So I tried debugging. Then I finally got an error message about using the wrong version of AIR. I opened up the JsonView-app.xml. There was no "setting" in here for AIR version, but then I saw this

<application xmlns="http://ns.adobe.com/air/application/1.0.M6">

Yep the .M6 was killing me. I removed it from the XML namespace declaration, and voila! Everything worked perfectly. Show your appreciation for my pain by downloading JsonViewer.

Monday, March 10, 2008

New developerWorks Article on WSAS and Eclipse

IBM published a new article I wrote last week. This one is titled WSAS and Eclipse simplify creating Web services. It is about the WSO2's Eclipse plugin that comes with their Web Services Application Server. The article shows how the plugin let's you take any POJO and turn it into a web service.

Sunday, March 09, 2008

Fantasy Baseball 2008

Oh yeah, it's that time of the year. Of all fantasy sports, baseball is without a doubt the best. I have had a mostly straightforward formula I have used over the years to rank players. This year's results top 30 (I did top 30 so I could squeeze in Tim Lincecum):

  1. Johan Santana 9.997069335

  2. Chase Utley 9.395566713

  3. Matt Holliday 9.28777674

  4. Alex Rodriguez 8.06973671

  5. Albert Pujols 7.362279704

  6. Jake Peavy 6.687233845

  7. Vladimir Guerrero 5.979646533

  8. Victor Martinez 5.724916421

  9. David Ortiz 5.661505849

  10. Ryan Howard 5.650694866

  11. Alfonso Soriano 5.226027058

  12. Carlos Lee 5.114022165

  13. Jonathan Papelbon 5.06406981

  14. Grady Sizemore 5.012756748

  15. Lance Berkman 4.721401161

  16. Hanley Ramirez 4.707462255

  17. Miguel Cabrera 4.202140221

  18. Jimmy Rollins 4.069476267

  19. J.J. Putz 4.013553495

  20. David Wright 4.007944434

  21. Joe Nathan 3.984203692

  22. Adam Dunn 3.907455051

  23. Mariano Rivera 3.793661698

  24. Prince Fielder 3.7901273

  25. C.C. Sabathia 3.749804343

  26. Russell Martin 3.703008847

  27. Carlos Beltran 3.629816436

  28. Ryan Braun 3.556328479

  29. Tim Lincecum 3.377436453

  30. Robinson Cano 3.376123846


The big weakness is always my source of projections. I prefer to be somewhat random about this. Sometimes I tweak based on personal bias. This year I did not. The numbers don't mean too much, unless you are in an auction league. In that case, a rating of 0 corresponds to the average price of a starting (non-bench) player. An increase of 1 point corresponds roughly to a 40% premium. So if rating(Player x) - rating(Player y) = 1.0, then $(Player X)/$(Player Y) = 1.4.

Thursday, March 06, 2008

IE-Hell Freezing Over

Even after I heard the rumors, I still never thought I'd see it with my own eyes:

My enthusiasm was quickly curbed when I tried to use IE8 to post this blog entry. Not only did the Blogger interface look crazy, but the upload image link did not work. I tried switching to "Emulate IE7". To do that, you must restart the browser. That's not very practical, and just means that most people will have to default to the IE7 emulator. Oh well, I guess Blogger just needs to fix up their non-standard JS? Maybe I will open up a debugger to figure out what is breaking. Probably some kind of browser sniffing code that picks different JS syntax depending on if it is IE or not. Maybe what is needed is an IE8 add-on that fakes the user-agent so that most sites think IE8 surfers are actually Firefox surfers.

Wednesday, March 05, 2008

More JRuby Performance

In the aftermath of my post on JRuby's performance, I exchanged some info with Mr. JRuby himself, Charles Nutter. Per his request, I opened a bug on the matter. It looks like it is a JVM issue, i.e. JRuby ran slowly on IBM's J9 JVM. I did some micro-benching on Ruby vs. JRuby on a variety of platforms and JVMs. It was only on the J9/2.3 (IBM's JDK 5.0 JVM) that JRuby was was slower than the latest "native" Ruby implementation on that platform. Everybody loves charts, so here are some fun ones.


This was on my MacBook, with both the standard HotSpot Java 5.0 and Java 6.0 preview versions. I also compared using the -J-server (just becomes -server for the JVM) option, since HotSpot on the Mac runs in client mode by default. Thus the -server made a big difference.

This was on my home desktop system, a 32-bit Windows Vista system. I only did native Ruby vs. JRuby with and without the -server option. Again JRuby with the -server option crushed native Ruby.

Finally the environment that caused all the problems, my workstation. As you can see, it did quite poor compared to native Ruby. However, JRuby with either the 5.0 or 6.0 HotSpot JVM was much faster. I was actually hoping to see a better performance advantage on the 6.0 VM vs. the 5.0 one... I don't have IBM's 6.0 VM, so I could not include it. The HotSpot VMs were both 64-bit, whereas the IBM J9 on was a 32-bit VM.

Tuesday, March 04, 2008

JRuby Performance

During my lunch today, I solved Problem 12 from Project Euler. As usual, I wrote the solution in Ruby and was surprised by just how long it took to calculate. It made me decide to try JRuby.

First, a note about the problem and my solution. The problem was to find the first triangle number (where the n_th triangle number is 1+2+3...+n) that has at least 500 divisors. My solution was pretty brute force. I took each triangle number and computed its prime factorization. For example 28 = 2^2 * 7^1. Thus the number of factors is (2+1)*(1+1) = 6. Generally if N = A^a * B^b * ... where A,B,.. are primes, then the number of factors is (a+1)*(b+1)*...

With all of that in mind, why did I think JRuby would be faster than Ruby on a problem like this? This kind of calculation is well suited for JVM optimizations: unwinding of loops, JIT'ing of the code, etc. Thus I thought this might be the kind of problem where the JVM could make JRuby run a lot faster than Ruby. Boy was I wrong!

In general, I found JRuby to take twice as long as plain ol' Ruby (or C Ruby as the JRuby folks like to call it.) This was true on Windows, where Ruby is considered to have a poor implementation by many, and on OSX.

This made me thing that my conjecture was wrong to begin with. Maybe this was not the kind of code that the JVM could do much with. I re-wrote the algorithm in Java and re-ran it. It was exponentially faster in Java than in Ruby or JRuby. Indeed, the JVM was able to optimize the runtime execution of the code and make it fly.

Is this what I should have expected? Is JRuby generally much slower than Ruby? I really thought that part of the idea behind JRuby was to leverage the JVM to make Ruby faster.